A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lena-x2-handover-measures.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 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: Manuel Requena <manuel.requena@cttc.es>
19  */
20 
21 #include "ns3/core-module.h"
22 #include "ns3/network-module.h"
23 #include "ns3/internet-module.h"
24 #include "ns3/mobility-module.h"
25 #include "ns3/lte-module.h"
26 #include "ns3/applications-module.h"
27 #include "ns3/point-to-point-module.h"
28 #include "ns3/config-store-module.h"
29 
30 #include <iomanip>
31 
32 using namespace ns3;
33 
34 NS_LOG_COMPONENT_DEFINE ("LenaX2HandoverMeasures");
35 
36 
44 int
45 main (int argc, char *argv[])
46 {
47  // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
48 
49  // LogComponentEnable ("LteHelper", logLevel);
50  // LogComponentEnable ("EpcHelper", logLevel);
51  // LogComponentEnable ("EpcEnbApplication", logLevel);
52  // LogComponentEnable ("EpcX2", logLevel);
53  // LogComponentEnable ("EpcSgwPgwApplication", logLevel);
54 
55  // LogComponentEnable ("LteEnbRrc", logLevel);
56  // LogComponentEnable ("LteEnbNetDevice", logLevel);
57  // LogComponentEnable ("LteUeRrc", logLevel);
58  // LogComponentEnable ("LteUeNetDevice", logLevel);
59 
60  uint16_t numberOfUes = 1;
61  uint16_t numberOfEnbs = 2;
62  uint16_t numBearersPerUe = 0;
63  double distance = 1000.0; // m
64  double yForUe = 1000.0; // m
65  double speed = 20; // m/s
66  double simTime = 3.0 * distance / speed; // 3000 m / 20 m/s = 150 secs
67  double enbTxPowerDbm = 20.0;
68 
69  // change some default attributes so that they are reasonable for
70  // this scenario, but do this before processing command line
71  // arguments, so that the user is allowed to override these settings
72  Config::SetDefault ("ns3::UdpClient::Interval", TimeValue (MilliSeconds(10)));
73  Config::SetDefault ("ns3::UdpClient::MaxPackets", UintegerValue(1000000));
74  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue(true));
75 
76  // Command line arguments
77  CommandLine cmd;
78  cmd.AddValue("simTime", "Total duration of the simulation (in seconds)", simTime);
79  cmd.AddValue("speed", "Speed of the UE (default = 20 m/s)", speed);
80  cmd.AddValue("enbTxPowerDbm", "TX power [dBm] used by HeNBs (defalut = 20.0)", enbTxPowerDbm);
81 
82  cmd.Parse(argc, argv);
83 
84 
85  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
86  Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
87  lteHelper->SetEpcHelper (epcHelper);
88  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
89 
90  Ptr<Node> pgw = epcHelper->GetPgwNode ();
91 
92  // Create a single RemoteHost
93  NodeContainer remoteHostContainer;
94  remoteHostContainer.Create (1);
95  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
96  InternetStackHelper internet;
97  internet.Install (remoteHostContainer);
98 
99  // Create the Internet
100  PointToPointHelper p2ph;
101  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
102  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
103  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
104  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
105  Ipv4AddressHelper ipv4h;
106  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
107  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
108  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
109 
110 
111  // Routing of the Internet Host (towards the LTE network)
112  Ipv4StaticRoutingHelper ipv4RoutingHelper;
113  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
114  // interface 0 is localhost, 1 is the p2p device
115  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
116 
117  NodeContainer ueNodes;
118  NodeContainer enbNodes;
119  enbNodes.Create (numberOfEnbs);
120  ueNodes.Create (numberOfUes);
121 
122  // Install Mobility Model in eNB
123  Ptr<ListPositionAllocator> enbPositionAlloc = CreateObject<ListPositionAllocator> ();
124  for (uint16_t i = 0; i < numberOfEnbs; i++)
125  {
126  Vector enbPosition (distance * (i + 1), distance, 0);
127  enbPositionAlloc->Add (enbPosition);
128  }
129  MobilityHelper enbMobility;
130  enbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
131  enbMobility.SetPositionAllocator(enbPositionAlloc);
132  enbMobility.Install(enbNodes);
133 
134  // Install Mobility Model in UE
135  MobilityHelper ueMobility;
136  ueMobility.SetMobilityModel ("ns3::ConstantVelocityMobilityModel");
137  ueMobility.Install(ueNodes);
138  ueNodes.Get (0)->GetObject<MobilityModel> ()->SetPosition (Vector (0, yForUe, 0));
139  ueNodes.Get (0)->GetObject<ConstantVelocityMobilityModel> ()->SetVelocity (Vector (speed, 0, 0));
140 
141  // Install LTE Devices in eNB and UEs
142  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (enbTxPowerDbm));
143  NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes);
144  NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes);
145 
146  // Install the IP stack on the UEs
147  internet.Install (ueNodes);
148  Ipv4InterfaceContainer ueIpIfaces;
149  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs));
150  // Assign IP address to UEs, and install applications
151  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
152  {
153  Ptr<Node> ueNode = ueNodes.Get (u);
154  // Set the default gateway for the UE
155  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
156  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
157  }
158 
159 
160  // Attach all UEs to the first eNodeB
161  for (uint16_t i = 0; i < numberOfUes; i++)
162  {
163  lteHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(0));
164  }
165 
166 
167  NS_LOG_LOGIC ("setting up applications");
168 
169  // Install and start applications on UEs and remote host
170  uint16_t dlPort = 10000;
171  uint16_t ulPort = 20000;
172 
173  // randomize a bit start times to avoid simulation artifacts
174  // (e.g., buffer overflows due to packet transmissions happening
175  // exactly at the same time)
176  Ptr<UniformRandomVariable> startTimeSeconds = CreateObject<UniformRandomVariable> ();
177  startTimeSeconds->SetAttribute ("Min", DoubleValue (0));
178  startTimeSeconds->SetAttribute ("Max", DoubleValue (0.010));
179 
180  for (uint32_t u = 0; u < numberOfUes; ++u)
181  {
182  Ptr<Node> ue = ueNodes.Get (u);
183  // Set the default gateway for the UE
184  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ue->GetObject<Ipv4> ());
185  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
186 
187  for (uint32_t b = 0; b < numBearersPerUe; ++b)
188  {
189  ++dlPort;
190  ++ulPort;
191 
194 
195  NS_LOG_LOGIC ("installing UDP DL app for UE " << u);
196  UdpClientHelper dlClientHelper (ueIpIfaces.GetAddress (u), dlPort);
197  clientApps.Add (dlClientHelper.Install (remoteHost));
198  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory",
200  serverApps.Add (dlPacketSinkHelper.Install (ue));
201 
202  NS_LOG_LOGIC ("installing UDP UL app for UE " << u);
203  UdpClientHelper ulClientHelper (remoteHostAddr, ulPort);
204  clientApps.Add (ulClientHelper.Install (ue));
205  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory",
207  serverApps.Add (ulPacketSinkHelper.Install (remoteHost));
208 
209  Ptr<EpcTft> tft = Create<EpcTft> ();
211  dlpf.localPortStart = dlPort;
212  dlpf.localPortEnd = dlPort;
213  tft->Add (dlpf);
215  ulpf.remotePortStart = ulPort;
216  ulpf.remotePortEnd = ulPort;
217  tft->Add (ulpf);
219  lteHelper->ActivateDedicatedEpsBearer (ueLteDevs.Get (u), bearer, tft);
220 
221  Time startTime = Seconds (startTimeSeconds->GetValue ());
222  serverApps.Start (startTime);
223  clientApps.Start (startTime);
224  } // end for b
225  }
226 
227 
228  // Add X2 inteface
229  lteHelper->AddX2Interface (enbNodes);
230 
231  // X2-based Handover
232 // lteHelper->HandoverRequest (Seconds (0.100), ueLteDevs.Get (0), enbLteDevs.Get (0), enbLteDevs.Get (1));
233 
234 
235  // Uncomment to enable PCAP tracing
236  //p2ph.EnablePcapAll("lena-x2-handover");
237 
238  lteHelper->EnablePhyTraces ();
239  lteHelper->EnableMacTraces ();
240  lteHelper->EnableRlcTraces ();
241  lteHelper->EnablePdcpTraces ();
242  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
243  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (1.0)));
244  Ptr<RadioBearerStatsCalculator> pdcpStats = lteHelper->GetPdcpStats ();
245  pdcpStats->SetAttribute ("EpochDuration", TimeValue (Seconds (1.0)));
246 
247 
248  Simulator::Stop(Seconds(simTime));
249  Simulator::Run();
250 
251  // GtkConfigStore config;
252  // config.ConfigureAttributes();
253 
255  return 0;
256 
257 }