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 <ios>
33 #include <string>
34 #include <vector>
35 
36 // The topology of this simulation program is inspired from
37 // 3GPP R4-092042, Section 4.2.1 Dual Stripe Model
38 // note that the term "apartments" used in that document matches with
39 // the term "room" used in the BuildingsMobilityModel
40 
41 using namespace ns3;
42 
43 
44 NS_LOG_COMPONENT_DEFINE ("LenaDualStripe");
45 
46 
47 bool AreOverlapping (Box a, Box b)
48 {
49  return !((a.xMin > b.xMax) || (b.xMin > a.xMax) || (a.yMin > b.yMax) || (b.yMin > a.yMax));
50 }
51 
53 {
54 public:
55  FemtocellBlockAllocator (Box area, uint32_t nApartmentsX, uint32_t nFloors);
56  void Create (uint32_t n);
57  void Create ();
58 
59 private:
60  bool OverlapsWithAnyPrevious (Box);
62  uint32_t m_nApartmentsX;
63  uint32_t m_nFloors;
64  std::list<Box> m_previousBlocks;
65  double m_xSize;
66  double m_ySize;
69 
70 };
71 
72 FemtocellBlockAllocator::FemtocellBlockAllocator (Box area, uint32_t nApartmentsX, uint32_t nFloors)
73  : m_area (area),
74  m_nApartmentsX (nApartmentsX),
75  m_nFloors (nFloors),
76  m_xSize (nApartmentsX*10 + 20),
77  m_ySize (70)
78 {
79  m_xMinVar = CreateObject<UniformRandomVariable> ();
80  m_xMinVar->SetAttribute ("Min", DoubleValue (area.xMin));
81  m_xMinVar->SetAttribute ("Max", DoubleValue (area.xMax - m_xSize));
82  m_yMinVar = CreateObject<UniformRandomVariable> ();
83  m_yMinVar->SetAttribute ("Min", DoubleValue (area.yMin));
84  m_yMinVar->SetAttribute ("Max", DoubleValue (area.yMax - m_ySize));
85 }
86 
87 void
89 {
90  for (uint32_t i = 0; i < n; ++i)
91  {
92  Create ();
93  }
94 }
95 
96 void
98 {
99  Box box;
100  uint32_t attempt = 0;
101  do
102  {
103  NS_ASSERT_MSG (attempt < 100, "Too many failed attemtps to position apartment block. Too many blocks? Too small area?");
104  box.xMin = m_xMinVar->GetValue ();
105  box.xMax = box.xMin + m_xSize;
106  box.yMin = m_yMinVar->GetValue ();
107  box.yMax = box.yMin + m_ySize;
108  ++attempt;
109  }
110  while (OverlapsWithAnyPrevious (box));
111 
112  NS_LOG_LOGIC ("allocated non overlapping block " << box);
113  m_previousBlocks.push_back (box);
114  Ptr<GridBuildingAllocator> gridBuildingAllocator;
115  gridBuildingAllocator = CreateObject<GridBuildingAllocator> ();
116  gridBuildingAllocator->SetAttribute ("GridWidth", UintegerValue (1));
117  gridBuildingAllocator->SetAttribute ("LengthX", DoubleValue (10*m_nApartmentsX));
118  gridBuildingAllocator->SetAttribute ("LengthY", DoubleValue (10*2));
119  gridBuildingAllocator->SetAttribute ("DeltaX", DoubleValue (10));
120  gridBuildingAllocator->SetAttribute ("DeltaY", DoubleValue (10));
121  gridBuildingAllocator->SetAttribute ("Height", DoubleValue (3*m_nFloors));
122  gridBuildingAllocator->SetBuildingAttribute ("NRoomsX", UintegerValue (m_nApartmentsX));
123  gridBuildingAllocator->SetBuildingAttribute ("NRoomsY", UintegerValue (2));
124  gridBuildingAllocator->SetBuildingAttribute ("NFloors", UintegerValue (m_nFloors));
125  gridBuildingAllocator->SetAttribute ("MinX", DoubleValue (box.xMin + 10));
126  gridBuildingAllocator->SetAttribute ("MinY", DoubleValue (box.yMin + 10));
127  gridBuildingAllocator->Create (2);
128 }
129 
130 bool
132 {
133  for (std::list<Box>::iterator it = m_previousBlocks.begin (); it != m_previousBlocks.end (); ++it)
134  {
135  if (AreOverlapping (*it, box))
136  {
137  return true;
138  }
139  }
140  return false;
141 }
142 
143 void
145 {
146  std::ofstream outFile;
147  outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
148  if (!outFile.is_open ())
149  {
150  NS_LOG_ERROR ("Can't open file " << filename);
151  return;
152  }
153  uint32_t index = 0;
154  for (BuildingList::Iterator it = BuildingList::Begin (); it != BuildingList::End (); ++it)
155  {
156  ++index;
157  Box box = (*it)->GetBoundaries ();
158  outFile << "set object " << index
159  << " rect from " << box.xMin << "," << box.yMin
160  << " to " << box.xMax << "," << box.yMax
161  << " front fs empty "
162  << std::endl;
163  }
164 }
165 
166 void
167 PrintGnuplottableUeListToFile (std::string filename)
168 {
169  std::ofstream outFile;
170  outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
171  if (!outFile.is_open ())
172  {
173  NS_LOG_ERROR ("Can't open file " << filename);
174  return;
175  }
176  for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
177  {
178  Ptr<Node> node = *it;
179  int nDevs = node->GetNDevices ();
180  for (int j = 0; j < nDevs; j++)
181  {
182  Ptr<LteUeNetDevice> uedev = node->GetDevice (j)->GetObject <LteUeNetDevice> ();
183  if (uedev)
184  {
185  Vector pos = node->GetObject<MobilityModel> ()->GetPosition ();
186  outFile << "set label \"" << uedev->GetImsi ()
187  << "\" 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"
188  << std::endl;
189  }
190  }
191  }
192 }
193 
194 void
195 PrintGnuplottableEnbListToFile (std::string filename)
196 {
197  std::ofstream outFile;
198  outFile.open (filename.c_str (), std::ios_base::out | std::ios_base::trunc);
199  if (!outFile.is_open ())
200  {
201  NS_LOG_ERROR ("Can't open file " << filename);
202  return;
203  }
204  for (NodeList::Iterator it = NodeList::Begin (); it != NodeList::End (); ++it)
205  {
206  Ptr<Node> node = *it;
207  int nDevs = node->GetNDevices ();
208  for (int j = 0; j < nDevs; j++)
209  {
210  Ptr<LteEnbNetDevice> enbdev = node->GetDevice (j)->GetObject <LteEnbNetDevice> ();
211  if (enbdev)
212  {
213  Vector pos = node->GetObject<MobilityModel> ()->GetPosition ();
214  outFile << "set label \"" << enbdev->GetCellId ()
215  << "\" 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"
216  << std::endl;
217  }
218  }
219  }
220 }
221 
222 
223 static ns3::GlobalValue g_nBlocks ("nBlocks",
224  "Number of femtocell blocks",
225  ns3::UintegerValue (1),
226  ns3::MakeUintegerChecker<uint32_t> ());
227 static ns3::GlobalValue g_nApartmentsX ("nApartmentsX",
228  "Number of apartments along the X axis in a femtocell block",
229  ns3::UintegerValue (10),
230  ns3::MakeUintegerChecker<uint32_t> ());
231 static ns3::GlobalValue g_nFloors ("nFloors",
232  "Number of floors",
233  ns3::UintegerValue (1),
234  ns3::MakeUintegerChecker<uint32_t> ());
235 static ns3::GlobalValue g_nMacroEnbSites ("nMacroEnbSites",
236  "How many macro sites there are",
237  ns3::UintegerValue (3),
238  ns3::MakeUintegerChecker<uint32_t> ());
239 static ns3::GlobalValue g_nMacroEnbSitesX ("nMacroEnbSitesX",
240  "(minimum) number of sites along the X-axis of the hex grid",
241  ns3::UintegerValue (1),
242  ns3::MakeUintegerChecker<uint32_t> ());
243 static ns3::GlobalValue g_interSiteDistance ("interSiteDistance",
244  "min distance between two nearby macro cell sites",
245  ns3::DoubleValue (500),
246  ns3::MakeDoubleChecker<double> ());
247 static ns3::GlobalValue g_areaMarginFactor ("areaMarginFactor",
248  "how much the UE area extends outside the macrocell grid, "
249  "expressed as fraction of the interSiteDistance",
250  ns3::DoubleValue (0.5),
251  ns3::MakeDoubleChecker<double> ());
252 static ns3::GlobalValue g_macroUeDensity ("macroUeDensity",
253  "How many macrocell UEs there are per square meter",
254  ns3::DoubleValue (0.00002),
255  ns3::MakeDoubleChecker<double> ());
256 static ns3::GlobalValue g_homeEnbDeploymentRatio ("homeEnbDeploymentRatio",
257  "The HeNB deployment ratio as per 3GPP R4-092042",
258  ns3::DoubleValue (0.2),
259  ns3::MakeDoubleChecker<double> ());
260 static ns3::GlobalValue g_homeEnbActivationRatio ("homeEnbActivationRatio",
261  "The HeNB activation ratio as per 3GPP R4-092042",
262  ns3::DoubleValue (0.5),
263  ns3::MakeDoubleChecker<double> ());
264 static ns3::GlobalValue g_homeUesHomeEnbRatio ("homeUesHomeEnbRatio",
265  "How many (on average) home UEs per HeNB there are in the simulation",
266  ns3::DoubleValue (1.0),
267  ns3::MakeDoubleChecker<double> ());
268 static ns3::GlobalValue g_macroEnbTxPowerDbm ("macroEnbTxPowerDbm",
269  "TX power [dBm] used by macro eNBs",
270  ns3::DoubleValue (46.0),
271  ns3::MakeDoubleChecker<double> ());
272 static ns3::GlobalValue g_homeEnbTxPowerDbm ("homeEnbTxPowerDbm",
273  "TX power [dBm] used by HeNBs",
274  ns3::DoubleValue (20.0),
275  ns3::MakeDoubleChecker<double> ());
276 static ns3::GlobalValue g_macroEnbDlEarfcn ("macroEnbDlEarfcn",
277  "DL EARFCN used by macro eNBs",
278  ns3::UintegerValue (100),
279  ns3::MakeUintegerChecker<uint16_t> ());
280 static ns3::GlobalValue g_homeEnbDlEarfcn ("homeEnbDlEarfcn",
281  "DL EARFCN used by HeNBs",
282  ns3::UintegerValue (100),
283  ns3::MakeUintegerChecker<uint16_t> ());
284 static ns3::GlobalValue g_macroEnbBandwidth ("macroEnbBandwidth",
285  "bandwidth [num RBs] used by macro eNBs",
286  ns3::UintegerValue (25),
287  ns3::MakeUintegerChecker<uint16_t> ());
288 static ns3::GlobalValue g_homeEnbBandwidth ("homeEnbBandwidth",
289  "bandwidth [num RBs] used by HeNBs",
290  ns3::UintegerValue (25),
291  ns3::MakeUintegerChecker<uint16_t> ());
292 static ns3::GlobalValue g_simTime ("simTime",
293  "Total duration of the simulation [s]",
294  ns3::DoubleValue (0.25),
295  ns3::MakeDoubleChecker<double> ());
296 static ns3::GlobalValue g_generateRem ("generateRem",
297  "if true, will generate a REM and then abort the simulation;"
298  "if false, will run the simulation normally (without generating any REM)",
299  ns3::BooleanValue (false),
300  ns3::MakeBooleanChecker ());
301 static ns3::GlobalValue g_epc ("epc",
302  "If true, will setup the EPC to simulate an end-to-end topology, "
303  "with real IP applications over PDCP and RLC UM (or RLC AM by changing "
304  "the default value of EpsBearerToRlcMapping e.g. to RLC_AM_ALWAYS). "
305  "If false, only the LTE radio access will be simulated with RLC SM. ",
306  ns3::BooleanValue (false),
307  ns3::MakeBooleanChecker ());
308 static ns3::GlobalValue g_epcDl ("epcDl",
309  "if true, will activate data flows in the downlink when EPC is being used. "
310  "If false, downlink flows won't be activated. "
311  "If EPC is not used, this parameter will be ignored.",
312  ns3::BooleanValue (true),
313  ns3::MakeBooleanChecker ());
314 static ns3::GlobalValue g_epcUl ("epcUl",
315  "if true, will activate data flows in the uplink when EPC is being used. "
316  "If false, uplink flows won't be activated. "
317  "If EPC is not used, this parameter will be ignored.",
318  ns3::BooleanValue (true),
319  ns3::MakeBooleanChecker ());
320 static ns3::GlobalValue g_useUdp ("useUdp",
321  "if true, the UdpClient application will be used. "
322  "Otherwise, the BulkSend application will be used over a TCP connection. "
323  "If EPC is not used, this parameter will be ignored.",
324  ns3::BooleanValue (true),
325  ns3::MakeBooleanChecker ());
326 static ns3::GlobalValue g_fadingTrace ("fadingTrace",
327  "The path of the fading trace (by default no fading trace "
328  "is loaded, i.e., fading is not considered)",
329  ns3::StringValue (""),
330  ns3::MakeStringChecker ());
331 static ns3::GlobalValue g_numBearersPerUe ("numBearersPerUe",
332  "How many bearers per UE there are in the simulation",
333  ns3::UintegerValue (1),
334  ns3::MakeUintegerChecker<uint16_t> ());
335 
336 static ns3::GlobalValue g_srsPeriodicity ("srsPeriodicity",
337  "SRS Periodicity (has to be at least greater than the number of UEs per eNB)",
338  ns3::UintegerValue (80),
339  ns3::MakeUintegerChecker<uint16_t> ());
340 
341 static ns3::GlobalValue g_outdoorUeMinSpeed ("outdoorUeMinSpeed",
342  "Minimum speed value of macor UE with random waypoint model [m/s].",
343  ns3::DoubleValue (0.0),
344  ns3::MakeDoubleChecker<double> ());
345 
346 static ns3::GlobalValue g_outdoorUeMaxSpeed ("outdoorUeMaxSpeed",
347  "Maximum speed value of macor UE with random waypoint model [m/s].",
348  ns3::DoubleValue (0.0),
349  ns3::MakeDoubleChecker<double> ());
350 
351 int
352 main (int argc, char *argv[])
353 {
354  // change some default attributes so that they are reasonable for
355  // this scenario, but do this before processing command line
356  // arguments, so that the user is allowed to override these settings
357  Config::SetDefault ("ns3::UdpClient::Interval", TimeValue (MilliSeconds (1)));
358  Config::SetDefault ("ns3::UdpClient::MaxPackets", UintegerValue (1000000));
359  Config::SetDefault ("ns3::LteRlcUm::MaxTxBufferSize", UintegerValue (10 * 1024));
360 
361  CommandLine cmd;
362  cmd.Parse (argc, argv);
363  ConfigStore inputConfig;
364  inputConfig.ConfigureDefaults ();
365  // parse again so you can override input file default values via command line
366  cmd.Parse (argc, argv);
367 
368  // the scenario parameters get their values from the global attributes defined above
369  UintegerValue uintegerValue;
370  DoubleValue doubleValue;
371  BooleanValue booleanValue;
372  StringValue stringValue;
373  GlobalValue::GetValueByName ("nBlocks", uintegerValue);
374  uint32_t nBlocks = uintegerValue.Get ();
375  GlobalValue::GetValueByName ("nApartmentsX", uintegerValue);
376  uint32_t nApartmentsX = uintegerValue.Get ();
377  GlobalValue::GetValueByName ("nFloors", uintegerValue);
378  uint32_t nFloors = uintegerValue.Get ();
379  GlobalValue::GetValueByName ("nMacroEnbSites", uintegerValue);
380  uint32_t nMacroEnbSites = uintegerValue.Get ();
381  GlobalValue::GetValueByName ("nMacroEnbSitesX", uintegerValue);
382  uint32_t nMacroEnbSitesX = uintegerValue.Get ();
383  GlobalValue::GetValueByName ("interSiteDistance", doubleValue);
384  double interSiteDistance = doubleValue.Get ();
385  GlobalValue::GetValueByName ("areaMarginFactor", doubleValue);
386  double areaMarginFactor = doubleValue.Get ();
387  GlobalValue::GetValueByName ("macroUeDensity", doubleValue);
388  double macroUeDensity = doubleValue.Get ();
389  GlobalValue::GetValueByName ("homeEnbDeploymentRatio", doubleValue);
390  double homeEnbDeploymentRatio = doubleValue.Get ();
391  GlobalValue::GetValueByName ("homeEnbActivationRatio", doubleValue);
392  double homeEnbActivationRatio = doubleValue.Get ();
393  GlobalValue::GetValueByName ("homeUesHomeEnbRatio", doubleValue);
394  double homeUesHomeEnbRatio = doubleValue.Get ();
395  GlobalValue::GetValueByName ("macroEnbTxPowerDbm", doubleValue);
396  double macroEnbTxPowerDbm = doubleValue.Get ();
397  GlobalValue::GetValueByName ("homeEnbTxPowerDbm", doubleValue);
398  double homeEnbTxPowerDbm = doubleValue.Get ();
399  GlobalValue::GetValueByName ("macroEnbDlEarfcn", uintegerValue);
400  uint16_t macroEnbDlEarfcn = uintegerValue.Get ();
401  GlobalValue::GetValueByName ("homeEnbDlEarfcn", uintegerValue);
402  uint16_t homeEnbDlEarfcn = uintegerValue.Get ();
403  GlobalValue::GetValueByName ("macroEnbBandwidth", uintegerValue);
404  uint16_t macroEnbBandwidth = uintegerValue.Get ();
405  GlobalValue::GetValueByName ("homeEnbBandwidth", uintegerValue);
406  uint16_t homeEnbBandwidth = uintegerValue.Get ();
407  GlobalValue::GetValueByName ("simTime", doubleValue);
408  double simTime = doubleValue.Get ();
409  GlobalValue::GetValueByName ("epc", booleanValue);
410  bool epc = booleanValue.Get ();
411  GlobalValue::GetValueByName ("epcDl", booleanValue);
412  bool epcDl = booleanValue.Get ();
413  GlobalValue::GetValueByName ("epcUl", booleanValue);
414  bool epcUl = booleanValue.Get ();
415  GlobalValue::GetValueByName ("useUdp", booleanValue);
416  bool useUdp = booleanValue.Get ();
417  GlobalValue::GetValueByName ("generateRem", booleanValue);
418  bool generateRem = booleanValue.Get ();
419  GlobalValue::GetValueByName ("fadingTrace", stringValue);
420  std::string fadingTrace = stringValue.Get ();
421  GlobalValue::GetValueByName ("numBearersPerUe", uintegerValue);
422  uint16_t numBearersPerUe = uintegerValue.Get ();
423  GlobalValue::GetValueByName ("srsPeriodicity", uintegerValue);
424  uint16_t srsPeriodicity = uintegerValue.Get ();
425  GlobalValue::GetValueByName ("outdoorUeMinSpeed", doubleValue);
426  uint16_t outdoorUeMinSpeed = doubleValue.Get ();
427  GlobalValue::GetValueByName ("outdoorUeMaxSpeed", doubleValue);
428  uint16_t outdoorUeMaxSpeed = doubleValue.Get ();
429 
430  Config::SetDefault ("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue(srsPeriodicity));
431 
432  Box macroUeBox;
433  double ueZ = 1.5;
434  if (nMacroEnbSites > 0)
435  {
436  uint32_t currentSite = nMacroEnbSites -1;
437  uint32_t biRowIndex = (currentSite / (nMacroEnbSitesX + nMacroEnbSitesX + 1));
438  uint32_t biRowRemainder = currentSite % (nMacroEnbSitesX + nMacroEnbSitesX + 1);
439  uint32_t rowIndex = biRowIndex*2 + 1;
440  if (biRowRemainder >= nMacroEnbSitesX)
441  {
442  ++rowIndex;
443  }
444  uint32_t nMacroEnbSitesY = rowIndex;
445  NS_LOG_LOGIC ("nMacroEnbSitesY = " << nMacroEnbSitesY);
446 
447  macroUeBox = Box (-areaMarginFactor*interSiteDistance,
448  (nMacroEnbSitesX + areaMarginFactor)*interSiteDistance,
449  -areaMarginFactor*interSiteDistance,
450  (nMacroEnbSitesY -1)*interSiteDistance*sqrt(0.75) + areaMarginFactor*interSiteDistance,
451  ueZ, ueZ);
452  }
453  else
454  {
455  // still need the box to place femtocell blocks
456  macroUeBox = Box (0, 150, 0, 150, ueZ, ueZ);
457  }
458 
459  FemtocellBlockAllocator blockAllocator (macroUeBox, nApartmentsX, nFloors);
460  blockAllocator.Create (nBlocks);
461 
462 
463  uint32_t nHomeEnbs = round (4 * nApartmentsX * nBlocks * nFloors * homeEnbDeploymentRatio * homeEnbActivationRatio);
464  NS_LOG_LOGIC ("nHomeEnbs = " << nHomeEnbs);
465  uint32_t nHomeUes = round (nHomeEnbs * homeUesHomeEnbRatio);
466  NS_LOG_LOGIC ("nHomeUes = " << nHomeUes);
467  double macroUeAreaSize = (macroUeBox.xMax - macroUeBox.xMin) * (macroUeBox.yMax - macroUeBox.yMin);
468  uint32_t nMacroUes = round (macroUeAreaSize * macroUeDensity) ;
469  NS_LOG_LOGIC ("nMacroUes = " << nMacroUes << " (density=" << macroUeDensity << ")");
470 
471  NodeContainer homeEnbs;
472  homeEnbs.Create (nHomeEnbs);
473  NodeContainer macroEnbs;
474  macroEnbs.Create (3 * nMacroEnbSites);
475  NodeContainer homeUes;
476  homeUes.Create (nHomeUes);
477  NodeContainer macroUes;
478  macroUes.Create (nMacroUes);
479 
480  MobilityHelper mobility;
481  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
482 
483 
484  Ptr <LteHelper> lteHelper = CreateObject<LteHelper> ();
485  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
486  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0));
487  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (1));
488  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (1.5));
489  // use always LOS model
490  lteHelper->SetPathlossModelAttribute ("Los2NlosThr", DoubleValue (1e6));
491  lteHelper->SetSpectrumChannelType ("ns3::MultiModelSpectrumChannel");
492 
493 // lteHelper->EnableLogComponents ();
494 // LogComponentEnable ("PfFfMacScheduler", LOG_LEVEL_ALL);
495 
496  if (!fadingTrace.empty ())
497  {
498  lteHelper->SetAttribute ("FadingModel", StringValue ("ns3::TraceFadingLossModel"));
499  lteHelper->SetFadingModelAttribute("TraceFilename", StringValue (fadingTrace));
500  }
501 
502  Ptr<EpcHelper> epcHelper;
503  if (epc)
504  {
505  NS_LOG_LOGIC ("enabling EPC");
506  epcHelper = CreateObject<EpcHelper> ();
507  lteHelper->SetEpcHelper (epcHelper);
508  }
509 
510  // Macro eNBs in 3-sector hex grid
511 
512  mobility.Install (macroEnbs);
513  BuildingsHelper::Install (macroEnbs);
514  Ptr<LteHexGridEnbTopologyHelper> lteHexGridEnbTopologyHelper = CreateObject<LteHexGridEnbTopologyHelper> ();
515  lteHexGridEnbTopologyHelper->SetLteHelper (lteHelper);
516  lteHexGridEnbTopologyHelper->SetAttribute ("InterSiteDistance", DoubleValue (interSiteDistance));
517  lteHexGridEnbTopologyHelper->SetAttribute ("MinX", DoubleValue (interSiteDistance/2));
518  lteHexGridEnbTopologyHelper->SetAttribute ("GridWidth", UintegerValue (nMacroEnbSitesX));
519  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (macroEnbTxPowerDbm));
520  lteHelper->SetEnbAntennaModelType ("ns3::ParabolicAntennaModel");
521  lteHelper->SetEnbAntennaModelAttribute ("Beamwidth", DoubleValue (70));
522  lteHelper->SetEnbAntennaModelAttribute ("MaxAttenuation", DoubleValue (20.0));
523  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (macroEnbDlEarfcn));
524  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (macroEnbDlEarfcn + 18000));
525  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (macroEnbBandwidth));
526  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (macroEnbBandwidth));
527  NetDeviceContainer macroEnbDevs = lteHexGridEnbTopologyHelper->SetPositionAndInstallEnbDevice (macroEnbs);
528 
529  if (epc)
530  {
531  // this enables handover for macro eNBs
532  lteHelper->AddX2Interface (macroEnbs);
533  }
534 
535  // HomeEnbs randomly indoor
536 
537  Ptr<PositionAllocator> positionAlloc = CreateObject<RandomRoomPositionAllocator> ();
538  mobility.SetPositionAllocator (positionAlloc);
539  mobility.Install (homeEnbs);
540  BuildingsHelper::Install (homeEnbs);
541  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (homeEnbTxPowerDbm));
542  lteHelper->SetEnbAntennaModelType ("ns3::IsotropicAntennaModel");
543  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (homeEnbDlEarfcn));
544  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (homeEnbDlEarfcn + 18000));
545  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (homeEnbBandwidth));
546  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (homeEnbBandwidth));
547  NetDeviceContainer homeEnbDevs = lteHelper->InstallEnbDevice (homeEnbs);
548 
549 
550  // home UEs located in the same apartment in which there are the Home eNBs
551  positionAlloc = CreateObject<SameRoomPositionAllocator> (homeEnbs);
552  mobility.SetPositionAllocator (positionAlloc);
553  mobility.Install (homeUes);
554  BuildingsHelper::Install (homeUes);
555  NetDeviceContainer homeUeDevs = lteHelper->InstallUeDevice (homeUes);
556 
557  // macro Ues
558  NS_LOG_LOGIC ("randomly allocating macro UEs in " << macroUeBox << " speedMin " << outdoorUeMinSpeed << " speedMax " << outdoorUeMaxSpeed);
559  if (outdoorUeMaxSpeed!=0.0)
560  {
561  mobility.SetMobilityModel ("ns3::SteadyStateRandomWaypointMobilityModel");
562 
563  Config::SetDefault ("ns3::SteadyStateRandomWaypointMobilityModel::MinX", DoubleValue (macroUeBox.xMin));
564  Config::SetDefault ("ns3::SteadyStateRandomWaypointMobilityModel::MinY", DoubleValue (macroUeBox.yMin));
565  Config::SetDefault ("ns3::SteadyStateRandomWaypointMobilityModel::MaxX", DoubleValue (macroUeBox.xMax));
566  Config::SetDefault ("ns3::SteadyStateRandomWaypointMobilityModel::MaxY", DoubleValue (macroUeBox.yMax));
567  Config::SetDefault ("ns3::SteadyStateRandomWaypointMobilityModel::Z", DoubleValue (ueZ));
568  Config::SetDefault ("ns3::SteadyStateRandomWaypointMobilityModel::MaxSpeed", DoubleValue (outdoorUeMaxSpeed));
569  Config::SetDefault ("ns3::SteadyStateRandomWaypointMobilityModel::MinSpeed", DoubleValue (outdoorUeMinSpeed));
570 
571  // this is not used since SteadyStateRandomWaypointMobilityModel
572  // takes care of initializing the positions; however we need to
573  // reset it since the previously used PositionAllocator
574  // (SameRoom) will cause an error when used with homeDeploymentRatio=0
575  positionAlloc = CreateObject<RandomBoxPositionAllocator> ();
576  mobility.SetPositionAllocator (positionAlloc);
577  mobility.Install (macroUes);
578 
579  // forcing initialization so we don't have to wait for Nodes to
580  // start before positions are assigned (which is needed to
581  // output node positions to file and to make AttachToClosestEnb work)
582  for (NodeContainer::Iterator it = macroUes.Begin ();
583  it != macroUes.End ();
584  ++it)
585  {
586  (*it)->Initialize ();
587  }
588  }
589  else
590  {
591  positionAlloc = CreateObject<RandomBoxPositionAllocator> ();
592  Ptr<UniformRandomVariable> xVal = CreateObject<UniformRandomVariable> ();
593  xVal->SetAttribute ("Min", DoubleValue (macroUeBox.xMin));
594  xVal->SetAttribute ("Max", DoubleValue (macroUeBox.xMax));
595  positionAlloc->SetAttribute ("X", PointerValue (xVal));
596  Ptr<UniformRandomVariable> yVal = CreateObject<UniformRandomVariable> ();
597  yVal->SetAttribute ("Min", DoubleValue (macroUeBox.yMin));
598  yVal->SetAttribute ("Max", DoubleValue (macroUeBox.yMax));
599  positionAlloc->SetAttribute ("Y", PointerValue (yVal));
600  Ptr<UniformRandomVariable> zVal = CreateObject<UniformRandomVariable> ();
601  zVal->SetAttribute ("Min", DoubleValue (macroUeBox.zMin));
602  zVal->SetAttribute ("Max", DoubleValue (macroUeBox.zMax));
603  positionAlloc->SetAttribute ("Z", PointerValue (zVal));
604  mobility.SetPositionAllocator (positionAlloc);
605  mobility.Install (macroUes);
606  }
607  BuildingsHelper::Install (macroUes);
608 
609  NetDeviceContainer macroUeDevs = lteHelper->InstallUeDevice (macroUes);
610 
611  Ipv4Address remoteHostAddr;
612  NodeContainer ues;
613  Ipv4StaticRoutingHelper ipv4RoutingHelper;
614  Ipv4InterfaceContainer ueIpIfaces;
615  Ptr<Node> remoteHost;
616  NetDeviceContainer ueDevs;
617  if (epc)
618  {
619  NS_LOG_LOGIC ("setting up internet and remote host");
620 
621  // Create a single RemoteHost
622  NodeContainer remoteHostContainer;
623  remoteHostContainer.Create (1);
624  remoteHost = remoteHostContainer.Get (0);
625  InternetStackHelper internet;
626  internet.Install (remoteHostContainer);
627 
628  // Create the Internet
629  PointToPointHelper p2ph;
630  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
631  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
632  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
633  Ptr<Node> pgw = epcHelper->GetPgwNode ();
634  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
635  Ipv4AddressHelper ipv4h;
636  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
637  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
638  // in this container, interface 0 is the pgw, 1 is the remoteHost
639  remoteHostAddr = internetIpIfaces.GetAddress (1);
640 
641  Ipv4StaticRoutingHelper ipv4RoutingHelper;
642  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
643  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
644 
645  // for internetworking purposes, consider together home UEs and macro UEs
646  ues.Add (homeUes);
647  ues.Add (macroUes);
648  ueDevs.Add (homeUeDevs);
649  ueDevs.Add (macroUeDevs);
650 
651  // Install the IP stack on the UEs
652  internet.Install (ues);
653  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
654  }
655 
656  // attachment (needs to be done after IP stack configuration)
657  // macro UEs attached to the closest macro eNB
658  lteHelper->AttachToClosestEnb (macroUeDevs, macroEnbDevs);
659  // each home UE is ttach explicitly to its home eNB
661  NetDeviceContainer::Iterator enbDevIt = homeEnbDevs.Begin ();
662 
663  for (ueDevIt = homeUeDevs.Begin ();
664  ueDevIt != homeUeDevs.End ();
665  ++ueDevIt, ++enbDevIt)
666  {
667  // this because of the order in which SameRoomPositionAllocator
668  // will place the UEs
669  if (enbDevIt == homeEnbDevs.End ())
670  {
671  enbDevIt = homeEnbDevs.Begin ();
672  }
673  lteHelper->Attach (*ueDevIt, *enbDevIt);
674  }
675 
676 
677  if (epc)
678  {
679  NS_LOG_LOGIC ("setting up applications");
680 
681  // Install and start applications on UEs and remote host
682  uint16_t dlPort = 10000;
683  uint16_t ulPort = 20000;
684 
685  // randomize a bit start times to avoid simulation artifacts
686  // (e.g., buffer overflows due to packet transmissions happening
687  // exactly at the same time)
688  Ptr<UniformRandomVariable> startTimeSeconds = CreateObject<UniformRandomVariable> ();
689  if (useUdp)
690  {
691  startTimeSeconds->SetAttribute ("Min", DoubleValue (0));
692  startTimeSeconds->SetAttribute ("Max", DoubleValue (0.010));
693  }
694  else
695  {
696  // TCP needs to be started late enough so that all UEs are connected
697  // otherwise TCP SYN packets will get lost
698  startTimeSeconds->SetAttribute ("Min", DoubleValue (0.100));
699  startTimeSeconds->SetAttribute ("Max", DoubleValue (0.110));
700  }
701 
702  for (uint32_t u = 0; u < ues.GetN (); ++u)
703  {
704  Ptr<Node> ue = ues.Get (u);
705  // Set the default gateway for the UE
706  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue->GetObject<Ipv4> ());
707  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
708 
709  for (uint32_t b = 0; b < numBearersPerUe; ++b)
710  {
711  ++dlPort;
712  ++ulPort;
713 
716 
717  if (useUdp)
718  {
719  if (epcDl)
720  {
721  NS_LOG_LOGIC ("installing UDP DL app for UE " << u);
722  UdpClientHelper dlClientHelper (ueIpIfaces.GetAddress (u), dlPort);
723  clientApps.Add (dlClientHelper.Install (remoteHost));
724  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory",
725  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
726  serverApps.Add (dlPacketSinkHelper.Install (ue));
727  }
728  if (epcUl)
729  {
730  NS_LOG_LOGIC ("installing UDP UL app for UE " << u);
731  UdpClientHelper ulClientHelper (remoteHostAddr, ulPort);
732  clientApps.Add (ulClientHelper.Install (ue));
733  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory",
734  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
735  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
736  }
737  }
738  else // use TCP
739  {
740  if (epcDl)
741  {
742  NS_LOG_LOGIC ("installing TCP DL app for UE " << u);
743  BulkSendHelper dlClientHelper ("ns3::TcpSocketFactory",
744  InetSocketAddress (ueIpIfaces.GetAddress (u), dlPort));
745  dlClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
746  clientApps.Add (dlClientHelper.Install (remoteHost));
747  PacketSinkHelper dlPacketSinkHelper ("ns3::TcpSocketFactory",
748  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
749  serverApps.Add (dlPacketSinkHelper.Install (ue));
750  }
751  if (epcUl)
752  {
753  NS_LOG_LOGIC ("installing TCP UL app for UE " << u);
754  BulkSendHelper ulClientHelper ("ns3::TcpSocketFactory",
755  InetSocketAddress (remoteHostAddr, ulPort));
756  ulClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
757  clientApps.Add (ulClientHelper.Install (ue));
758  PacketSinkHelper ulPacketSinkHelper ("ns3::TcpSocketFactory",
759  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
760  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
761  }
762  } // end if (useUdp)
763 
764  Ptr<EpcTft> tft = Create<EpcTft> ();
765  if (epcDl)
766  {
768  dlpf.localPortStart = dlPort;
769  dlpf.localPortEnd = dlPort;
770  tft->Add (dlpf);
771  }
772  if (epcUl)
773  {
775  ulpf.remotePortStart = ulPort;
776  ulpf.remotePortEnd = ulPort;
777  tft->Add (ulpf);
778  }
779 
780  if (epcDl || epcUl)
781  {
782  EpsBearer bearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT);
783  lteHelper->ActivateDedicatedEpsBearer (ueDevs.Get (u), bearer, tft);
784  }
785  Time startTime = Seconds (startTimeSeconds->GetValue ());
786  serverApps.Start (startTime);
787  clientApps.Start (startTime);
788 
789  } // end for b
790  }
791 
792  }
793  else // (epc == false)
794  {
795  // for radio bearer activation purposes, consider together home UEs and macro UEs
796  NetDeviceContainer ueDevs;
797  ueDevs.Add (homeUeDevs);
798  ueDevs.Add (macroUeDevs);
799  for (uint32_t u = 0; u < ueDevs.GetN (); ++u)
800  {
801  Ptr<NetDevice> ueDev = ueDevs.Get (u);
802  for (uint32_t b = 0; b < numBearersPerUe; ++b)
803  {
804  enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
805  EpsBearer bearer (q);
806  lteHelper->ActivateDataRadioBearer (ueDev, bearer);
807  }
808  }
809  }
810 
811  BuildingsHelper::MakeMobilityModelConsistent ();
812 
814  if (generateRem)
815  {
816  PrintGnuplottableBuildingListToFile ("buildings.txt");
817  PrintGnuplottableEnbListToFile ("enbs.txt");
818  PrintGnuplottableUeListToFile ("ues.txt");
819 
820  remHelper = CreateObject<RadioEnvironmentMapHelper> ();
821  remHelper->SetAttribute ("ChannelPath", StringValue ("/ChannelList/0"));
822  remHelper->SetAttribute ("OutputFile", StringValue ("lena-dual-stripe.rem"));
823  remHelper->SetAttribute ("XMin", DoubleValue (macroUeBox.xMin));
824  remHelper->SetAttribute ("XMax", DoubleValue (macroUeBox.xMax));
825  remHelper->SetAttribute ("YMin", DoubleValue (macroUeBox.yMin));
826  remHelper->SetAttribute ("YMax", DoubleValue (macroUeBox.yMax));
827  remHelper->SetAttribute ("Z", DoubleValue (1.5));
828  remHelper->Install ();
829  // simulation will stop right after the REM has been generated
830  }
831  else
832  {
833  Simulator::Stop (Seconds (simTime));
834  }
835 
836  lteHelper->EnableMacTraces ();
837  lteHelper->EnableRlcTraces ();
838  if (epc)
839  {
840  lteHelper->EnablePdcpTraces ();
841  }
842 
843  Simulator::Run ();
844 
845  //GtkConfigStore config;
846  //config.ConfigureAttributes ();
847 
848  lteHelper = 0;
849  Simulator::Destroy ();
850  return 0;
851 }