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 }
holds a vector of ns3::Application pointers.
uint8_t Add(PacketFilter f)
Definition: epc-tft.cc:157
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
an Inet address class
static Ipv4Address GetAny(void)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Hold a bool native type.
Definition: boolean.h:38
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Definition: lte-helper.cc:301
holds a vector of std::pair of Ptr and interface index.
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr 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. ...
static void Run(void)
Definition: simulator.cc:157
void EnableRlcTraces(void)
Definition: lte-helper.cc:849
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.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
a 3d vector
Definition: vector.h:31
ApplicationContainer Install(NodeContainer c)
tuple clientApps
Definition: first.py:53
void SetSchedulerType(std::string type)
Definition: lte-helper.cc:193
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
Definition: data-rate.h:71
void EnablePdcpTraces(void)
Definition: lte-helper.cc:986
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:828
Hold an unsigned integer type.
Definition: uinteger.h:46
double startTime
void Attach(NetDeviceContainer ueDevices, Ptr< NetDevice > enbDevice)
Definition: lte-helper.cc:582
holds a vector of ns3::NetDevice pointers
void EnablePhyTraces(void)
Definition: lte-helper.cc:897
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 arguments.
Definition: command-line.h:152
#define NS_LOG_LOGIC(msg)
Definition: log.h:334
static void Destroy(void)
Definition: simulator.cc:121
tuple serverApps
Definition: first.py:44
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:75
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
void ActivateDedicatedEpsBearer(NetDeviceContainer ueDevices, EpsBearer bearer, Ptr< EpcTft > tft)
Definition: lte-helper.cc:649
keep track of a set of node pointers.
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
void AddX2Interface(NodeContainer enbNodes)
Definition: lte-helper.cc:747
void SetChannelAttribute(std::string name, const AttributeValue &value)
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:980
NetDeviceContainer InstallUeDevice(NodeContainer c)
Definition: lte-helper.cc:316
Ptr< RadioBearerStatsCalculator > GetPdcpStats(void)
Definition: lte-helper.cc:994
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.
int main(int argc, char *argv[])
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...
NS_LOG_COMPONENT_DEFINE("PacketLossCounter")
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
void SetEpcHelper(Ptr< EpcHelper > h)
Definition: lte-helper.cc:186
static void SetVelocity(Ptr< Node > node, Vector vel)
Definition: bug780-test.cc:54
Helper class that adds ns3::Ipv4StaticRouting objects.
hold objects of type ns3::DataRate
void AddValue(const std::string &name, const std::string &help, T &value)
Definition: command-line.h:408
static void Stop(void)
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Mobility model for which the current speed does not change once it has been set and until it is set a...
ApplicationContainer Install(NodeContainer c) const
void Parse(int argc, char *argv[])
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static void SetPosition(Ptr< Node > node, Vector position)
void EnableMacTraces(void)
Definition: lte-helper.cc:937
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
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:360
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const