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 int
222 main (int argc, char *argv[])
223 {
224  // change some default attributes so that they are reasonable for
225  // this scenario, but do this before processing command line
226  // arguments, so that the user is allowed to override these settings
227  Config::SetDefault ("ns3::UdpClient::Interval", TimeValue (MilliSeconds(1)));
228  Config::SetDefault ("ns3::UdpClient::MaxPackets", UintegerValue(1000000));
229 
230  // scenario parameters
231  uint32_t nBlocks = 10;
232  uint32_t nApartmentsX = 10;
233  uint32_t nFloors = 1;
234  uint32_t nMacroEnbSites = 3;
235  uint32_t nMacroEnbSitesX = 1;
236  double interSiteDistance = 500;
237  double areaMarginFactor = 0.5;
238  double macroUeDensity = 0.0001;
239  double homeEnbDeploymentRatio = 0.2;
240  double homeEnbActivationRatio = 0.5;
241  double homeUesHomeEnbRatio = 1;
242  double macroEnbTxPowerDbm = 46.0;
243  double homeEnbTxPowerDbm = 20.0;
244  uint16_t macroEnbDlEarfcn = 100;
245  uint16_t homeEnbDlEarfcn = 100;
246  uint16_t macroEnbBandwidth = 25;
247  uint16_t homeEnbBandwidth = 25;
248  double simTime = 0.25;
249  bool epc = false;
250  bool epcDl = true;
251  bool epcUl = true;
252  bool useUdp = true;
253  bool generateRem = false;
254  std::string fadingFileTrace = "";
255 
256  CommandLine cmd;
257  cmd.AddValue ("nBlocks", "Number of femtocell blocks", nBlocks);
258  cmd.AddValue ("nApartmentsX", "Number of apartments along the X axis in a femtocell block", nApartmentsX);
259  cmd.AddValue ("nFloors", "Number of floors", nFloors);
260  cmd.AddValue ("nMacroEnbSites", "How many macro sites there are", nMacroEnbSites);
261  cmd.AddValue ("nMacroEnbSitesX",
262  "(minimum) number of sites along the X-axis of the hex grid", nMacroEnbSitesX);
263  cmd.AddValue ("interSiteDistance", "min distance between two nearby macro cell sites", interSiteDistance);
264  cmd.AddValue ("areaMarginFactor", "how much the UE area extends outside the macrocell grid, "
265  "expressed as fraction of the interSiteDistance", areaMarginFactor);
266  cmd.AddValue ("macroUeDensity", "How many macrocell UEs there are per square meter", macroUeDensity);
267  cmd.AddValue ("homeEnbDeploymentRatio",
268  "The HeNB deployment ratio as per 3GPP R4-092042", homeEnbDeploymentRatio);
269  cmd.AddValue ("homeEnbActivationRatio",
270  "The HeNB activation ratio as per 3GPP R4-092042", homeEnbActivationRatio);
271  cmd.AddValue ("homeUesHomeEnbRatio",
272  "How many (on average) home UEs per HeNB there are in the simulation",
273  homeUesHomeEnbRatio);
274  cmd.AddValue ("macroEnbTxPowerDbm", "TX power [dBm] used by macro eNBs", macroEnbTxPowerDbm);
275  cmd.AddValue ("homeEnbTxPowerDbm", "TX power [dBm] used by HeNBs", homeEnbTxPowerDbm);
276  cmd.AddValue ("macroEnbDlEarfcn", "DL EARFCN used by macro eNBs", macroEnbDlEarfcn);
277  cmd.AddValue ("homeEnbDlEarfcn", "DL EARFCN used by HeNBs", homeEnbDlEarfcn);
278  cmd.AddValue ("macroEnbBandwidth", "bandwdith [num RBs] used by macro eNBs", macroEnbBandwidth);
279  cmd.AddValue ("homeEnbBandwidth", "bandwdith [num RBs] used by HeNBs", homeEnbBandwidth);
280  cmd.AddValue ("simTime", "Total duration of the simulation [s]", simTime);
281  cmd.AddValue ("generateRem", "if true, will generate a REM and then abort the simulation;"
282  "if false, will run the simulation normally (without generating any REM)", generateRem);
283  cmd.AddValue ("epc", "if true, will setup the EPC to simulate an end-to-end topology;"
284  "if false, only the LTE radio access will be simulated.", epc);
285  cmd.AddValue ("epcDl", "if true, will activate data flows in the downlink when EPC is being used. "
286  "If false, downlink flows won't be activated. "
287  "If EPC is not used, this parameter will be ignored.", epcDl);
288  cmd.AddValue ("epcUl", "if true, will activate data flows in the uplink when EPC is being used. "
289  "If false, uplink flows won't be activated. "
290  "If EPC is not used, this parameter will be ignored.", epcUl);
291  cmd.AddValue ("useUdp", "if true, the UdpClient application will be used. "
292  "Otherwise, the BulkSend application will be used over a TCP connection. "
293  "If EPC is not used, this parameter will be ignored.", useUdp);
294  cmd.AddValue ("fadingTrace", "The path of the fading trace (by default any fading trace is loadedm which implies that fading is not considered)", fadingFileTrace);
295 
296 
297  cmd.Parse (argc, argv);
298 
299  ConfigStore inputConfig;
300  inputConfig.ConfigureDefaults ();
301 
302  cmd.Parse (argc, argv);
303 
304  Box macroUeBox;
305 
306  if (nMacroEnbSites > 0)
307  {
308  uint32_t currentSite = nMacroEnbSites -1;
309  uint32_t biRowIndex = (currentSite / (nMacroEnbSitesX + nMacroEnbSitesX + 1));
310  uint32_t biRowRemainder = currentSite % (nMacroEnbSitesX + nMacroEnbSitesX + 1);
311  uint32_t rowIndex = biRowIndex*2 + 1;
312  if (biRowRemainder >= nMacroEnbSitesX)
313  {
314  ++rowIndex;
315  }
316  uint32_t nMacroEnbSitesY = rowIndex;
317  NS_LOG_LOGIC ("nMacroEnbSitesY = " << nMacroEnbSitesY);
318 
319  macroUeBox = Box (-areaMarginFactor*interSiteDistance,
320  (nMacroEnbSitesX + areaMarginFactor)*interSiteDistance,
321  -areaMarginFactor*interSiteDistance,
322  (nMacroEnbSitesY -1)*interSiteDistance*sqrt(0.75) + areaMarginFactor*interSiteDistance,
323  1.0, 2.0);
324  }
325  else
326  {
327  // still need the box to place femtocell blocks
328  macroUeBox = Box (0, 150, 0, 150, 1.0, 2.0);
329  }
330 
331  FemtocellBlockAllocator blockAllocator (macroUeBox, nApartmentsX, nFloors);
332  blockAllocator.Create (nBlocks);
333 
334 
335  uint32_t nHomeEnbs = round (4 * nApartmentsX * nBlocks * nFloors * homeEnbDeploymentRatio * homeEnbActivationRatio);
336  NS_LOG_LOGIC ("nHomeEnbs = " << nHomeEnbs);
337  uint32_t nHomeUes = round (nHomeEnbs * homeUesHomeEnbRatio);
338  NS_LOG_LOGIC ("nHomeUes = " << nHomeUes);
339  double macroUeAreaSize = (macroUeBox.xMax - macroUeBox.xMin) * (macroUeBox.yMax - macroUeBox.yMin);
340  uint32_t nMacroUes = round (macroUeAreaSize * macroUeDensity) ;
341  NS_LOG_LOGIC ("nMacroUes = " << nMacroUes << " (density=" << macroUeDensity << ")");
342 
343  NodeContainer homeEnbs;
344  homeEnbs.Create (nHomeEnbs);
345  NodeContainer macroEnbs;
346  macroEnbs.Create (3 * nMacroEnbSites);
347  NodeContainer homeUes;
348  homeUes.Create (nHomeUes);
349  NodeContainer macroUes;
350  macroUes.Create (nMacroUes);
351 
352  MobilityHelper mobility;
353  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
354 
355 
356  Ptr <LteHelper> lteHelper = CreateObject<LteHelper> ();
357  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
358  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0));
359  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (1));
360  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (1.5));
361  // use always LOS model
362  lteHelper->SetPathlossModelAttribute ("Los2NlosThr", DoubleValue (1e6));
363  lteHelper->SetSpectrumChannelType ("ns3::MultiModelSpectrumChannel");
364 
365  if (!fadingFileTrace.empty ())
366  {
367  lteHelper->SetAttribute ("FadingModel", StringValue ("ns3::TraceFadingLossModel"));
368  lteHelper->SetFadingModelAttribute("TraceFilename", StringValue (fadingFileTrace));
369  }
370 
371  Ptr<EpcHelper> epcHelper;
372  if (epc)
373  {
374  NS_LOG_LOGIC ("enabling EPC");
375  epcHelper = CreateObject<EpcHelper> ();
376  lteHelper->SetEpcHelper (epcHelper);
377  }
378 
379  // Macro eNBs in 3-sector hex grid
380 
381  mobility.Install (macroEnbs);
382  Ptr<LteHexGridEnbTopologyHelper> lteHexGridEnbTopologyHelper = CreateObject<LteHexGridEnbTopologyHelper> ();
383  lteHexGridEnbTopologyHelper->SetLteHelper (lteHelper);
384  lteHexGridEnbTopologyHelper->SetAttribute ("InterSiteDistance", DoubleValue (interSiteDistance));
385  lteHexGridEnbTopologyHelper->SetAttribute ("MinX", DoubleValue (interSiteDistance/2));
386  lteHexGridEnbTopologyHelper->SetAttribute ("GridWidth", UintegerValue (nMacroEnbSitesX));
387  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (macroEnbTxPowerDbm));
388  lteHelper->SetEnbAntennaModelType ("ns3::ParabolicAntennaModel");
389  lteHelper->SetEnbAntennaModelAttribute ("Beamwidth", DoubleValue (70));
390  lteHelper->SetEnbAntennaModelAttribute ("MaxAttenuation", DoubleValue (20.0));
391  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (macroEnbDlEarfcn));
392  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (macroEnbDlEarfcn + 18000));
393  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (macroEnbBandwidth));
394  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (macroEnbBandwidth));
395  NetDeviceContainer macroEnbDevs = lteHexGridEnbTopologyHelper->SetPositionAndInstallEnbDevice (macroEnbs);
396 
397 
398  // HomeEnbs randomly indoor
399 
400  Ptr<PositionAllocator> positionAlloc = CreateObject<RandomRoomPositionAllocator> ();
401  mobility.SetPositionAllocator (positionAlloc);
402  mobility.Install (homeEnbs);
403  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (homeEnbTxPowerDbm));
404  lteHelper->SetEnbAntennaModelType ("ns3::IsotropicAntennaModel");
405  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (homeEnbDlEarfcn));
406  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (homeEnbDlEarfcn + 18000));
407  lteHelper->SetEnbDeviceAttribute ("DlBandwidth", UintegerValue (homeEnbBandwidth));
408  lteHelper->SetEnbDeviceAttribute ("UlBandwidth", UintegerValue (homeEnbBandwidth));
409  NetDeviceContainer homeEnbDevs = lteHelper->InstallEnbDevice (homeEnbs);
410 
411 
412  // macro Ues
413  NS_LOG_LOGIC ("randomly allocating macro UEs in " << macroUeBox);
414  positionAlloc = CreateObject<RandomBoxPositionAllocator> ();
415  Ptr<UniformRandomVariable> xVal = CreateObject<UniformRandomVariable> ();
416  xVal->SetAttribute ("Min", DoubleValue (macroUeBox.xMin));
417  xVal->SetAttribute ("Max", DoubleValue (macroUeBox.xMax));
418  positionAlloc->SetAttribute ("X", PointerValue (xVal));
419  Ptr<UniformRandomVariable> yVal = CreateObject<UniformRandomVariable> ();
420  yVal->SetAttribute ("Min", DoubleValue (macroUeBox.yMin));
421  yVal->SetAttribute ("Max", DoubleValue (macroUeBox.yMax));
422  positionAlloc->SetAttribute ("Y", PointerValue (yVal));
423  Ptr<UniformRandomVariable> zVal = CreateObject<UniformRandomVariable> ();
424  zVal->SetAttribute ("Min", DoubleValue (macroUeBox.zMin));
425  zVal->SetAttribute ("Max", DoubleValue (macroUeBox.zMax));
426  positionAlloc->SetAttribute ("Z", PointerValue (zVal));
427  mobility.SetPositionAllocator (positionAlloc);
428  mobility.Install (macroUes);
429  NetDeviceContainer macroUeDevs = lteHelper->InstallUeDevice (macroUes);
430  lteHelper->AttachToClosestEnb (macroUeDevs, macroEnbDevs);
431 
432 
433  // home UEs located in the same apartment in which there are the Home eNBs
434  positionAlloc = CreateObject<SameRoomPositionAllocator> (homeEnbs);
435  mobility.SetPositionAllocator (positionAlloc);
436  mobility.Install (homeUes);
437  NetDeviceContainer homeUeDevs = lteHelper->InstallUeDevice (homeUes);
438 
440  NetDeviceContainer::Iterator enbDevIt = homeEnbDevs.Begin ();
441  // attach explicitly each home UE to its home eNB
442  for (ueDevIt = homeUeDevs.Begin ();
443  ueDevIt != homeUeDevs.End ();
444  ++ueDevIt, ++enbDevIt)
445  {
446  // this because of the order in which SameRoomPositionAllocator
447  // will place the UEs
448  if (enbDevIt == homeEnbDevs.End ())
449  {
450  enbDevIt = homeEnbDevs.Begin ();
451  }
452  lteHelper->Attach (*ueDevIt, *enbDevIt);
453  }
454 
455 
456  if (epc)
457  {
458  NS_LOG_LOGIC ("setting up internet, remote host and applications");
459 
460  // Create a single RemoteHost
461  NodeContainer remoteHostContainer;
462  remoteHostContainer.Create (1);
463  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
464  InternetStackHelper internet;
465  internet.Install (remoteHostContainer);
466 
467  // Create the Internet
468  PointToPointHelper p2ph;
469  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
470  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
471  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
472  Ptr<Node> pgw = epcHelper->GetPgwNode ();
473  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
474  Ipv4AddressHelper ipv4h;
475  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
476  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
477  // in this container, interface 0 is the pgw, 1 is the remoteHost
478  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
479 
480  Ipv4StaticRoutingHelper ipv4RoutingHelper;
481  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
482  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
483 
484  // for internetworking purposes, consider together home UEs and macro UEs
485  NodeContainer ues;
486  ues.Add (homeUes);
487  ues.Add (macroUes);
488  NetDeviceContainer ueDevs;
489  ueDevs.Add (homeUeDevs);
490  ueDevs.Add (macroUeDevs);
491 
492  // Install the IP stack on the UEs
493  internet.Install (ues);
494  Ipv4InterfaceContainer ueIpIfaces;
495  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
496 
497  // Install and start applications on UEs and remote host
498  uint16_t dlPort = 10000;
499  uint16_t ulPort = 20000;
500 
501  ApplicationContainer clientApps;
502  ApplicationContainer serverApps;
503  for (uint32_t u = 0; u < ues.GetN (); ++u)
504  {
505  Ptr<Node> ue = ues.Get (u);
506  // Set the default gateway for the UE
507  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue->GetObject<Ipv4> ());
508  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
509  ++dlPort;
510  ++ulPort;
511  if (useUdp)
512  {
513  if (epcDl)
514  {
515  NS_LOG_LOGIC ("installing UDP DL app for UE " << u);
516  UdpClientHelper dlClientHelper (ueIpIfaces.GetAddress (u), dlPort);
517  clientApps.Add (dlClientHelper.Install (remoteHost));
518  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory",
519  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
520  serverApps.Add (dlPacketSinkHelper.Install (ue));
521  }
522  if (epcUl)
523  {
524  NS_LOG_LOGIC ("installing UDP UL app for UE " << u);
525  UdpClientHelper ulClientHelper (remoteHostAddr, ulPort);
526  clientApps.Add (ulClientHelper.Install (ue));
527  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory",
528  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
529  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
530  }
531  }
532  else // use TCP
533  {
534  if (epcDl)
535  {
536  NS_LOG_LOGIC ("installing TCP DL app for UE " << u);
537  BulkSendHelper dlClientHelper ("ns3::TcpSocketFactory",
538  InetSocketAddress (ueIpIfaces.GetAddress (u), dlPort));
539  dlClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
540  clientApps.Add (dlClientHelper.Install (remoteHost));
541  PacketSinkHelper dlPacketSinkHelper ("ns3::TcpSocketFactory",
542  InetSocketAddress (Ipv4Address::GetAny (), dlPort));
543  serverApps.Add (dlPacketSinkHelper.Install (ue));
544  }
545  if (epcUl)
546  {
547  NS_LOG_LOGIC ("installing TCP UL app for UE " << u);
548  BulkSendHelper ulClientHelper ("ns3::TcpSocketFactory",
549  InetSocketAddress (remoteHostAddr, ulPort));
550  ulClientHelper.SetAttribute ("MaxBytes", UintegerValue (0));
551  clientApps.Add (ulClientHelper.Install (ue));
552  PacketSinkHelper ulPacketSinkHelper ("ns3::TcpSocketFactory",
553  InetSocketAddress (Ipv4Address::GetAny (), ulPort));
554  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
555  }
556  }
557  }
558  serverApps.Start (Seconds (0.0));
559  clientApps.Start (Seconds (0.0));
560 
561  } // end if (epc)
562 
563 
564 
565  // activate bearer for all UEs
566  enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
567  EpsBearer bearer (q);
568  lteHelper->ActivateEpsBearer (homeUeDevs, bearer, EpcTft::Default ());
569  lteHelper->ActivateEpsBearer (macroUeDevs, bearer, EpcTft::Default ());
570 
571 
572 
573  BuildingsHelper::MakeMobilityModelConsistent ();
574 
576  if (generateRem)
577  {
578  PrintGnuplottableBuildingListToFile ("buildings.txt");
579  PrintGnuplottableEnbListToFile ("enbs.txt");
580  PrintGnuplottableUeListToFile ("ues.txt");
581 
582  remHelper = CreateObject<RadioEnvironmentMapHelper> ();
583  remHelper->SetAttribute ("ChannelPath", StringValue ("/ChannelList/0"));
584  remHelper->SetAttribute ("OutputFile", StringValue ("lena-dual-stripe.rem"));
585  remHelper->SetAttribute ("XMin", DoubleValue (macroUeBox.xMin));
586  remHelper->SetAttribute ("XMax", DoubleValue (macroUeBox.xMax));
587  remHelper->SetAttribute ("YMin", DoubleValue (macroUeBox.yMin));
588  remHelper->SetAttribute ("YMax", DoubleValue (macroUeBox.yMax));
589  remHelper->SetAttribute ("Z", DoubleValue (1.5));
590  remHelper->Install ();
591  // simulation will stop right after the REM has been generated
592 
593 
594  }
595  else
596  {
597  Simulator::Stop (Seconds (simTime));
598  }
599 
600  lteHelper->EnableMacTraces ();
601  lteHelper->EnableRlcTraces ();
602  if (epc)
603  {
604  lteHelper->EnablePdcpTraces ();
605  }
606 
607  Simulator::Run ();
608 
609  //GtkConfigStore config;
610  //config.ConfigureAttributes ();
611 
612  lteHelper = 0;
613  Simulator::Destroy ();
614  return 0;
615 }