A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lena-dual-stripe.cc
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);
61  Box m_area;
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
88 FemtocellBlockAllocator::Create (uint32_t n)
89 {
90  for (uint32_t i = 0; i < n; ++i)
91  {
92  Create ();
93  }
94 }
95 
96 void
97 FemtocellBlockAllocator::Create ()
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
131 FemtocellBlockAllocator::OverlapsWithAnyPrevious (Box box)
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
144 PrintGnuplottableBuildingListToFile (std::string filename)
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 (10),
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.0001),
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 int
342 main (int argc, char *argv[])
343 {
344  // change some default attributes so that they are reasonable for
345  // this scenario, but do this before processing command line
346  // arguments, so that the user is allowed to override these settings
347  Config::SetDefault ("ns3::UdpClient::Interval", TimeValue (MilliSeconds(1)));
348  Config::SetDefault ("ns3::UdpClient::MaxPackets", UintegerValue(1000000));
349 
350  CommandLine cmd;
351  cmd.Parse (argc, argv);
352  ConfigStore inputConfig;
353  inputConfig.ConfigureDefaults ();
354  // parse again so you can override input file default values via command line
355  cmd.Parse (argc, argv);
356 
357  // the scenario parameters get their values from the global attributes defined above
358  UintegerValue uintegerValue;
359  DoubleValue doubleValue;
360  BooleanValue booleanValue;
361  StringValue stringValue;
362  GlobalValue::GetValueByName ("nBlocks", uintegerValue);
363  uint32_t nBlocks = uintegerValue.Get ();
364  GlobalValue::GetValueByName ("nApartmentsX", uintegerValue);
365  uint32_t nApartmentsX = uintegerValue.Get ();
366  GlobalValue::GetValueByName ("nFloors", uintegerValue);
367  uint32_t nFloors = uintegerValue.Get ();
368  GlobalValue::GetValueByName ("nMacroEnbSites", uintegerValue);
369  uint32_t nMacroEnbSites = uintegerValue.Get ();
370  GlobalValue::GetValueByName ("nMacroEnbSitesX", uintegerValue);
371  uint32_t nMacroEnbSitesX = uintegerValue.Get ();
372  GlobalValue::GetValueByName ("interSiteDistance", doubleValue);
373  double interSiteDistance = doubleValue.Get ();
374  GlobalValue::GetValueByName ("areaMarginFactor", doubleValue);
375  double areaMarginFactor = doubleValue.Get ();
376  GlobalValue::GetValueByName ("macroUeDensity", doubleValue);
377  double macroUeDensity = doubleValue.Get ();
378  GlobalValue::GetValueByName ("homeEnbDeploymentRatio", doubleValue);
379  double homeEnbDeploymentRatio = doubleValue.Get ();
380  GlobalValue::GetValueByName ("homeEnbActivationRatio", doubleValue);
381  double homeEnbActivationRatio = doubleValue.Get ();
382  GlobalValue::GetValueByName ("homeUesHomeEnbRatio", doubleValue);
383  double homeUesHomeEnbRatio = doubleValue.Get ();
384  GlobalValue::GetValueByName ("macroEnbTxPowerDbm", doubleValue);
385  double macroEnbTxPowerDbm = doubleValue.Get ();
386  GlobalValue::GetValueByName ("homeEnbTxPowerDbm", doubleValue);
387  double homeEnbTxPowerDbm = doubleValue.Get ();
388  GlobalValue::GetValueByName ("macroEnbDlEarfcn", uintegerValue);
389  uint16_t macroEnbDlEarfcn = uintegerValue.Get ();
390  GlobalValue::GetValueByName ("homeEnbDlEarfcn", uintegerValue);
391  uint16_t homeEnbDlEarfcn = uintegerValue.Get ();
392  GlobalValue::GetValueByName ("macroEnbBandwidth", uintegerValue);
393  uint16_t macroEnbBandwidth = uintegerValue.Get ();
394  GlobalValue::GetValueByName ("homeEnbBandwidth", uintegerValue);
395  uint16_t homeEnbBandwidth = uintegerValue.Get ();
396  GlobalValue::GetValueByName ("simTime", doubleValue);
397  double simTime = doubleValue.Get ();
398  GlobalValue::GetValueByName ("epc", booleanValue);
399  bool epc = booleanValue.Get ();
400  GlobalValue::GetValueByName ("epcDl", booleanValue);
401  bool epcDl = booleanValue.Get ();
402  GlobalValue::GetValueByName ("epcUl", booleanValue);
403  bool epcUl = booleanValue.Get ();
404  GlobalValue::GetValueByName ("useUdp", booleanValue);
405  bool useUdp = booleanValue.Get ();
406  GlobalValue::GetValueByName ("generateRem", booleanValue);
407  bool generateRem = booleanValue.Get ();
408  GlobalValue::GetValueByName ("fadingTrace", stringValue);
409  std::string fadingTrace = stringValue.Get ();
410  GlobalValue::GetValueByName ("numBearersPerUe", uintegerValue);
411  uint16_t numBearersPerUe = uintegerValue.Get ();
412  GlobalValue::GetValueByName ("srsPeriodicity", uintegerValue);
413  uint16_t srsPeriodicity = uintegerValue.Get ();
414 
415  Config::SetDefault ("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue(srsPeriodicity));
416 
417  Box macroUeBox;
418 
419  if (nMacroEnbSites > 0)
420  {
421  uint32_t currentSite = nMacroEnbSites -1;
422  uint32_t biRowIndex = (currentSite / (nMacroEnbSitesX + nMacroEnbSitesX + 1));
423  uint32_t biRowRemainder = currentSite % (nMacroEnbSitesX + nMacroEnbSitesX + 1);
424  uint32_t rowIndex = biRowIndex*2 + 1;
425  if (biRowRemainder >= nMacroEnbSitesX)
426  {
427  ++rowIndex;
428  }
429  uint32_t nMacroEnbSitesY = rowIndex;
430  NS_LOG_LOGIC ("nMacroEnbSitesY = " << nMacroEnbSitesY);
431 
432  macroUeBox = Box (-areaMarginFactor*interSiteDistance,
433  (nMacroEnbSitesX + areaMarginFactor)*interSiteDistance,
434  -areaMarginFactor*interSiteDistance,
435  (nMacroEnbSitesY -1)*interSiteDistance*sqrt(0.75) + areaMarginFactor*interSiteDistance,
436  1.0, 2.0);
437  }
438  else
439  {
440  // still need the box to place femtocell blocks
441  macroUeBox = Box (0, 150, 0, 150, 1.0, 2.0);
442  }
443 
444  FemtocellBlockAllocator blockAllocator (macroUeBox, nApartmentsX, nFloors);
445  blockAllocator.Create (nBlocks);
446 
447 
448  uint32_t nHomeEnbs = round (4 * nApartmentsX * nBlocks * nFloors * homeEnbDeploymentRatio * homeEnbActivationRatio);
449  NS_LOG_LOGIC ("nHomeEnbs = " << nHomeEnbs);
450  uint32_t nHomeUes = round (nHomeEnbs * homeUesHomeEnbRatio);
451  NS_LOG_LOGIC ("nHomeUes = " << nHomeUes);
452  double macroUeAreaSize = (macroUeBox.xMax - macroUeBox.xMin) * (macroUeBox.yMax - macroUeBox.yMin);
453  uint32_t nMacroUes = round (macroUeAreaSize * macroUeDensity) ;
454  NS_LOG_LOGIC ("nMacroUes = " << nMacroUes << " (density=" << macroUeDensity << ")");
455 
456  NodeContainer homeEnbs;
457  homeEnbs.Create (nHomeEnbs);
458  NodeContainer macroEnbs;
459  macroEnbs.Create (3 * nMacroEnbSites);
460  NodeContainer homeUes;
461  homeUes.Create (nHomeUes);
462  NodeContainer macroUes;
463  macroUes.Create (nMacroUes);
464 
465  MobilityHelper mobility;
466  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
467 
468 
469  Ptr <LteHelper> lteHelper = CreateObject<LteHelper> ();
470  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
471  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0));
472  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (1));
473  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (1.5));
474  // use always LOS model
475  lteHelper->SetPathlossModelAttribute ("Los2NlosThr", DoubleValue (1e6));
476  lteHelper->SetSpectrumChannelType ("ns3::MultiModelSpectrumChannel");
477 
478 // lteHelper->EnableLogComponents ();
479 // LogComponentEnable ("PfFfMacScheduler", LOG_LEVEL_ALL);
480 
481  if (!fadingTrace.empty ())
482  {
483  lteHelper->SetAttribute ("FadingModel", StringValue ("ns3::TraceFadingLossModel"));
484  lteHelper->SetFadingModelAttribute("TraceFilename", StringValue (fadingTrace));
485  }
486 
487  Ptr<EpcHelper> epcHelper;
488  if (epc)
489  {
490  NS_LOG_LOGIC ("enabling EPC");
491  epcHelper = CreateObject<EpcHelper> ();
492  lteHelper->SetEpcHelper (epcHelper);
493  }
494 
495  // Macro eNBs in 3-sector hex grid
496 
497  mobility.Install (macroEnbs);
498  Ptr<LteHexGridEnbTopologyHelper> lteHexGridEnbTopologyHelper = CreateObject<LteHexGridEnbTopologyHelper> ();
499  lteHexGridEnbTopologyHelper->SetLteHelper (lteHelper);
500  lteHexGridEnbTopologyHelper->SetAttribute ("InterSiteDistance", DoubleValue (interSiteDistance));
501  lteHexGridEnbTopologyHelper->SetAttribute ("MinX", DoubleValue (interSiteDistance/2));
502  lteHexGridEnbTopologyHelper->SetAttribute ("GridWidth", UintegerValue (nMacroEnbSitesX));
503  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (macroEnbTxPowerDbm));
504  lteHelper->SetEnbAntennaModelType ("ns3::ParabolicAntennaModel");
505  lteHelper->SetEnbAntennaModelAttribute ("Beamwidth", DoubleValue (70));
506  lteHelper->SetEnbAntennaModelAttribute ("MaxAttenuation", DoubleValue (20.0));
507  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (macroEnbDlEarfcn));
508  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (macroEnbDlEarfcn + 18000));
509  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (macroEnbBandwidth));
510  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (macroEnbBandwidth));
511  NetDeviceContainer macroEnbDevs = lteHexGridEnbTopologyHelper->SetPositionAndInstallEnbDevice (macroEnbs);
512 
513 
514  // HomeEnbs randomly indoor
515 
516  Ptr<PositionAllocator> positionAlloc = CreateObject<RandomRoomPositionAllocator> ();
517  mobility.SetPositionAllocator (positionAlloc);
518  mobility.Install (homeEnbs);
519  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (homeEnbTxPowerDbm));
520  lteHelper->SetEnbAntennaModelType ("ns3::IsotropicAntennaModel");
521  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (homeEnbDlEarfcn));
522  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (homeEnbDlEarfcn + 18000));
523  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (homeEnbBandwidth));
524  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (homeEnbBandwidth));
525  NetDeviceContainer homeEnbDevs = lteHelper->InstallEnbDevice (homeEnbs);
526 
527 
528  // macro Ues
529  NS_LOG_LOGIC ("randomly allocating macro UEs in " << macroUeBox);
530  positionAlloc = CreateObject<RandomBoxPositionAllocator> ();
531  Ptr<UniformRandomVariable> xVal = CreateObject<UniformRandomVariable> ();
532  xVal->SetAttribute ("Min", DoubleValue (macroUeBox.xMin));
533  xVal->SetAttribute ("Max", DoubleValue (macroUeBox.xMax));
534  positionAlloc->SetAttribute ("X", PointerValue (xVal));
535  Ptr<UniformRandomVariable> yVal = CreateObject<UniformRandomVariable> ();
536  yVal->SetAttribute ("Min", DoubleValue (macroUeBox.yMin));
537  yVal->SetAttribute ("Max", DoubleValue (macroUeBox.yMax));
538  positionAlloc->SetAttribute ("Y", PointerValue (yVal));
539  Ptr<UniformRandomVariable> zVal = CreateObject<UniformRandomVariable> ();
540  zVal->SetAttribute ("Min", DoubleValue (macroUeBox.zMin));
541  zVal->SetAttribute ("Max", DoubleValue (macroUeBox.zMax));
542  positionAlloc->SetAttribute ("Z", PointerValue (zVal));
543  mobility.SetPositionAllocator (positionAlloc);
544  mobility.Install (macroUes);
545  NetDeviceContainer macroUeDevs = lteHelper->InstallUeDevice (macroUes);
546 
547 
548  // home UEs located in the same apartment in which there are the Home eNBs
549  positionAlloc = CreateObject<SameRoomPositionAllocator> (homeEnbs);
550  mobility.SetPositionAllocator (positionAlloc);
551  mobility.Install (homeUes);
552  NetDeviceContainer homeUeDevs = lteHelper->InstallUeDevice (homeUes);
553 
554  Ipv4Address remoteHostAddr;
555  NodeContainer ues;
556  Ipv4StaticRoutingHelper ipv4RoutingHelper;
557  Ipv4InterfaceContainer ueIpIfaces;
558  Ptr<Node> remoteHost;
559  NetDeviceContainer ueDevs;
560  if (epc)
561  {
562  NS_LOG_LOGIC ("setting up internet and remote host");
563 
564  // Create a single RemoteHost
565  NodeContainer remoteHostContainer;
566  remoteHostContainer.Create (1);
567  remoteHost = remoteHostContainer.Get (0);
568  InternetStackHelper internet;
569  internet.Install (remoteHostContainer);
570 
571  // Create the Internet
572  PointToPointHelper p2ph;
573  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
574  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
575  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
576  Ptr<Node> pgw = epcHelper->GetPgwNode ();
577  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
578  Ipv4AddressHelper ipv4h;
579  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
580  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
581  // in this container, interface 0 is the pgw, 1 is the remoteHost
582  remoteHostAddr = internetIpIfaces.GetAddress (1);
583 
584  Ipv4StaticRoutingHelper ipv4RoutingHelper;
585  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
586  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
587 
588  // for internetworking purposes, consider together home UEs and macro UEs
589  ues.Add (homeUes);
590  ues.Add (macroUes);
591  ueDevs.Add (homeUeDevs);
592  ueDevs.Add (macroUeDevs);
593 
594  // Install the IP stack on the UEs
595  internet.Install (ues);
596  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
597  }
598 
599  // attachment (needs to be done after IP stack configuration)
600  // macro UEs attached to the closest macro eNB
601  lteHelper->AttachToClosestEnb (macroUeDevs, macroEnbDevs);
602  // each home UE is ttach explicitly to its home eNB
603  NetDeviceContainer::Iterator ueDevIt;
604  NetDeviceContainer::Iterator enbDevIt = homeEnbDevs.Begin ();
605 
606  for (ueDevIt = homeUeDevs.Begin ();
607  ueDevIt != homeUeDevs.End ();
608  ++ueDevIt, ++enbDevIt)
609  {
610  // this because of the order in which SameRoomPositionAllocator
611  // will place the UEs
612  if (enbDevIt == homeEnbDevs.End ())
613  {
614  enbDevIt = homeEnbDevs.Begin ();
615  }
616  lteHelper->Attach (*ueDevIt, *enbDevIt);
617  }
618 
619 
620 
621  if (epc)
622  {
623  NS_LOG_LOGIC ("setting up applications");
624 
625  // Install and start applications on UEs and remote host
626  uint16_t dlPort = 10000;
627  uint16_t ulPort = 20000;
628 
629  // randomize a bit start times to avoid simulation artifacts
630  // (e.g., buffer overflows due to packet transmissions happening
631  // exactly at the same time)
632  Ptr<UniformRandomVariable> startTimeSeconds = CreateObject<UniformRandomVariable> ();
633  if (useUdp)
634  {
635  startTimeSeconds->SetAttribute ("Min", DoubleValue (0));
636  startTimeSeconds->SetAttribute ("Max", DoubleValue (0.010));
637  }
638  else
639  {
640  // TCP needs to be started late enough so that all UEs are connected
641  // otherwise TCP SYN packets will get lost
642  startTimeSeconds->SetAttribute ("Min", DoubleValue (0.100));
643  startTimeSeconds->SetAttribute ("Max", DoubleValue (0.110));
644  }
645 
646 
647  for (uint32_t u = 0; u < ues.GetN (); ++u)
648  {
649  Ptr<Node> ue = ues.Get (u);
650  // Set the default gateway for the UE
651  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue->GetObject<Ipv4> ());
652  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
653 
654  for (uint32_t b = 0; b < numBearersPerUe; ++b)
655  {
656  ++dlPort;
657  ++ulPort;
658 
659  ApplicationContainer clientApps;
660  ApplicationContainer serverApps;
661 
662  if (useUdp)
663  {
664  if (epcDl)
665  {
666  NS_LOG_LOGIC ("installing UDP DL app for UE " << u);
667  UdpClientHelper dlClientHelper (ueIpIfaces.GetAddress (u), dlPort);
668  clientApps.Add (dlClientHelper.Install (remoteHost));
669  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory",
670  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
671  serverApps.Add (dlPacketSinkHelper.Install (ue));
672  }
673  if (epcUl)
674  {
675  NS_LOG_LOGIC ("installing UDP UL app for UE " << u);
676  UdpClientHelper ulClientHelper (remoteHostAddr, ulPort);
677  clientApps.Add (ulClientHelper.Install (ue));
678  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory",
679  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
680  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
681  }
682  }
683  else // use TCP
684  {
685  if (epcDl)
686  {
687  NS_LOG_LOGIC ("installing TCP DL app for UE " << u);
688  BulkSendHelper dlClientHelper ("ns3::TcpSocketFactory",
689  InetSocketAddress (ueIpIfaces.GetAddress (u), dlPort));
690  dlClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
691  clientApps.Add (dlClientHelper.Install (remoteHost));
692  PacketSinkHelper dlPacketSinkHelper ("ns3::TcpSocketFactory",
693  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
694  serverApps.Add (dlPacketSinkHelper.Install (ue));
695  }
696  if (epcUl)
697  {
698  NS_LOG_LOGIC ("installing TCP UL app for UE " << u);
699  BulkSendHelper ulClientHelper ("ns3::TcpSocketFactory",
700  InetSocketAddress (remoteHostAddr, ulPort));
701  ulClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
702  clientApps.Add (ulClientHelper.Install (ue));
703  PacketSinkHelper ulPacketSinkHelper ("ns3::TcpSocketFactory",
704  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
705  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
706  }
707  } // end if (useUdp)
708 
709  Ptr<EpcTft> tft = Create<EpcTft> ();
710  if (epcDl)
711  {
713  dlpf.localPortStart = dlPort;
714  dlpf.localPortEnd = dlPort;
715  tft->Add (dlpf);
716  }
717  if (epcUl)
718  {
720  ulpf.remotePortStart = ulPort;
721  ulpf.remotePortEnd = ulPort;
722  tft->Add (ulpf);
723  }
724 
725  if (epcDl || epcUl)
726  {
727  EpsBearer bearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT);
728  lteHelper->ActivateDedicatedEpsBearer (ueDevs.Get (u), bearer, tft);
729  }
730  Time startTime = Seconds (startTimeSeconds->GetValue ());
731  serverApps.Start (startTime);
732  clientApps.Start (startTime);
733 
734  } // end for b
735  }
736 
737  }
738  else // (epc == false)
739  {
740  // for radio bearer activation purposes, consider together home UEs and macro UEs
741  NetDeviceContainer ueDevs;
742  ueDevs.Add (homeUeDevs);
743  ueDevs.Add (macroUeDevs);
744  for (uint32_t u = 0; u < ueDevs.GetN (); ++u)
745  {
746  Ptr<NetDevice> ueDev = ueDevs.Get (u);
747  for (uint32_t b = 0; b < numBearersPerUe; ++b)
748  {
749  enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
750  EpsBearer bearer (q);
751  lteHelper->ActivateDataRadioBearer (ueDev, bearer);
752  }
753  }
754  }
755 
756  BuildingsHelper::MakeMobilityModelConsistent ();
757 
759  if (generateRem)
760  {
761  PrintGnuplottableBuildingListToFile ("buildings.txt");
762  PrintGnuplottableEnbListToFile ("enbs.txt");
763  PrintGnuplottableUeListToFile ("ues.txt");
764 
765  remHelper = CreateObject<RadioEnvironmentMapHelper> ();
766  remHelper->SetAttribute ("ChannelPath", StringValue ("/ChannelList/0"));
767  remHelper->SetAttribute ("OutputFile", StringValue ("lena-dual-stripe.rem"));
768  remHelper->SetAttribute ("XMin", DoubleValue (macroUeBox.xMin));
769  remHelper->SetAttribute ("XMax", DoubleValue (macroUeBox.xMax));
770  remHelper->SetAttribute ("YMin", DoubleValue (macroUeBox.yMin));
771  remHelper->SetAttribute ("YMax", DoubleValue (macroUeBox.yMax));
772  remHelper->SetAttribute ("Z", DoubleValue (1.5));
773  remHelper->Install ();
774  // simulation will stop right after the REM has been generated
775 
776 
777  }
778  else
779  {
780  Simulator::Stop (Seconds (simTime));
781  }
782 
783  lteHelper->EnableMacTraces ();
784  lteHelper->EnableRlcTraces ();
785  if (epc)
786  {
787  lteHelper->EnablePdcpTraces ();
788  }
789 
790  Simulator::Run ();
791 
792  //GtkConfigStore config;
793  //config.ConfigureAttributes ();
794 
795  lteHelper = 0;
796  Simulator::Destroy ();
797  return 0;
798 }
holds a vector of ns3::Application pointers.
double x
Definition: vector.h:49
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
uint8_t Add(PacketFilter f)
Definition: epc-tft.cc:157
keep track of time unit.
Definition: nstime.h:149
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Definition: lte-helper.cc:209
an Inet address class
Hold a bool native type.
Definition: boolean.h:38
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Definition: lte-helper.cc:285
A helper to make it easier to instantiate an ns3::BulkSendApplication on a set of nodes...
holds a vector of std::pair of Ptr<Ipv4> and interface index.
uint16_t GetCellId() const
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
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.
NetDeviceContainer Install(NodeContainer c)
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container. ...
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
void EnableRlcTraces(void)
Definition: lte-helper.cc:829
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
hold a so-called 'global value'.
Definition: global-value.h:47
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Definition: lte-helper.cc:773
void SetDeviceAttribute(std::string name, const AttributeValue &value)
a 3d vector
Definition: vector.h:31
NetDeviceContainer SetPositionAndInstallEnbDevice(NodeContainer c)
Ptr< Node > GetPgwNode()
Definition: epc-helper.cc:319
a 3d box
Definition: box.h:33
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
uint32_t GetN(void) const
Get the number of Ptr<NetDevice> stored in this container.
Class for representing data rates.
Definition: data-rate.h:71
void EnablePdcpTraces(void)
Definition: lte-helper.cc:1339
void AttachToClosestEnb(NetDeviceContainer ueDevices, NetDeviceContainer enbDevices)
Definition: lte-helper.cc:597
Keep track of the current position and velocity of an object.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Create a client application which sends udp packets carrying a 32bit sequence number and a 64 bit tim...
hold objects of type ns3::Time
Definition: nstime.h:700
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
BuildingContainer Create(uint32_t n) const
Hold an unsigned integer type.
Definition: uinteger.h:46
void Attach(NetDeviceContainer ueDevices, Ptr< NetDevice > enbDevice)
Definition: lte-helper.cc:562
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > GetDevice(uint32_t index) const
Definition: node.cc:133
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
parse command-line argumentsInstances of this class can be used to parse command-line arguments: user...
Definition: command-line.h:50
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
void SetEnbAntennaModelType(std::string type)
Definition: lte-helper.cc:225
void SetSpectrumChannelType(std::string type)
Definition: lte-helper.cc:271
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:75
uint32_t GetNDevices(void) const
Definition: node.cc:141
void SetFadingModelAttribute(std::string n, const AttributeValue &v)
Definition: lte-helper.cc:265
void ActivateDedicatedEpsBearer(NetDeviceContainer ueDevices, EpsBearer bearer, Ptr< EpcTft > tft)
Definition: lte-helper.cc:629
keep track of a set of node pointers.
hold objects of type Ptr<T>
Definition: pointer.h:33
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 Install(std::string nodeName) const
double y
Definition: vector.h:53
void SetChannelAttribute(std::string name, const AttributeValue &value)
#define NS_ASSERT_MSG(condition, message)
Definition: assert.h:86
NetDeviceContainer InstallUeDevice(NodeContainer c)
Definition: lte-helper.cc:300
void SetBuildingAttribute(std::string n, const AttributeValue &v)
Helper class used to assign positions and mobility models to nodes.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices)
Definition: epc-helper.cc:326
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
void SetEpcHelper(Ptr< EpcHelper > h)
Definition: lte-helper.cc:176
Helper class that adds ns3::Ipv4StaticRouting objects.
hold objects of type ns3::DataRate
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 SetEnbAntennaModelAttribute(std::string n, const AttributeValue &v)
Definition: lte-helper.cc:232
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.
Definition: nstime.h:601
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
#define NS_LOG_ERROR(msg)
Definition: log.h:237
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)
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
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
Ipv4Address GetUeDefaultGatewayAddress()
Definition: epc-helper.cc:334
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void SetEnbDeviceAttribute(std::string n, const AttributeValue &v)
Definition: lte-helper.cc:217
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const