From 40464355bf70c77f139f6c445134ccd3a43961d3 Mon Sep 17 00:00:00 2001 From: Manuel Requena Date: Thu, 28 Jun 2012 13:40:58 +0200 Subject: [PATCH] Add draft of X2 handover example --- src/lte/examples/lena-x2-handover.cc | 158 +++++++++++++++++++++++++++ src/lte/wscript | 6 + 2 files changed, 164 insertions(+) create mode 100644 src/lte/examples/lena-x2-handover.cc diff --git a/src/lte/examples/lena-x2-handover.cc b/src/lte/examples/lena-x2-handover.cc new file mode 100644 index 000000000..cf999912a --- /dev/null +++ b/src/lte/examples/lena-x2-handover.cc @@ -0,0 +1,158 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Manuel Requena + */ + +#include "ns3/core-module.h" +#include "ns3/network-module.h" +#include "ns3/internet-module.h" +#include "ns3/mobility-module.h" +#include "ns3/lte-module.h" +#include "ns3/applications-module.h" +#include "ns3/point-to-point-module.h" +#include "ns3/config-store.h" +//#include "ns3/gtk-config-store.h" + +using namespace ns3; + +/** + * Sample simulation script for a X2-based handover. + * It instantiates two eNodeB, attaches one UE to the 'source' eNB and + * triggers a handover of the UE towards the 'target' eNB. + */ +NS_LOG_COMPONENT_DEFINE ("EpcX2HandoverExample"); +int +main (int argc, char *argv[]) +{ + LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL); + + LogComponentEnable ("LteHelper", logLevel); + LogComponentEnable ("EpcHelper", logLevel); + LogComponentEnable ("EpcEnbApplication", logLevel); + LogComponentEnable ("EpcX2", logLevel); + LogComponentEnable ("EpcSgwPgwApplication", logLevel); + + LogComponentEnable ("LteEnbRrc", logLevel); + LogComponentEnable ("LteEnbNetDevice", logLevel); + LogComponentEnable ("LteUeRrc", logLevel); + LogComponentEnable ("LteUeNetDevice", logLevel); + + uint16_t numberOfUes = 1; + uint16_t numberOfEnbs = 2; + double simTime = 4.0; + double distance = 60.0; + + // Command line arguments + CommandLine cmd; + cmd.AddValue("numberOfUes", "Number of UEs", numberOfUes); + cmd.AddValue("numberOfEnbs", "Number of eNodeBs", numberOfEnbs); + cmd.AddValue("simTime", "Total duration of the simulation (in seconds)",simTime); + cmd.Parse(argc, argv); + + + Ptr lteHelper = CreateObject (); + Ptr epcHelper = CreateObject (); + lteHelper->SetEpcHelper (epcHelper); + lteHelper->SetSchedulerType("ns3::RrFfMacScheduler"); + + Ptr pgw = epcHelper->GetPgwNode (); + + // Create a single RemoteHost + NodeContainer remoteHostContainer; + remoteHostContainer.Create (1); + Ptr remoteHost = remoteHostContainer.Get (0); + InternetStackHelper internet; + internet.Install (remoteHostContainer); + + // Create the Internet + PointToPointHelper p2ph; + p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); + p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500)); + p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010))); + NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); + Ipv4AddressHelper ipv4h; + ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); + Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices); + + // Routing of the Internet Host (towards the LTE network) + Ipv4StaticRoutingHelper ipv4RoutingHelper; + Ptr remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject ()); + // interface 0 is localhost, 1 is the p2p device + remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1); + + NodeContainer ueNodes; + NodeContainer enbNodes; + enbNodes.Create(numberOfEnbs); + ueNodes.Create(numberOfUes); + + // Install Mobility Model + Ptr positionAlloc = CreateObject (); + for (uint16_t i = 0; i < numberOfEnbs; i++) + { + positionAlloc->Add (Vector(distance * i, 0, 0)); + } + MobilityHelper mobility; + mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); + mobility.SetPositionAllocator(positionAlloc); + mobility.Install(enbNodes); + mobility.Install(ueNodes); + + // Install LTE Devices in eNB and UEs + NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes); + NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes); + + // Attach all UEs to the first eNodeB + for (uint16_t i = 0; i < numberOfUes; i++) + { + lteHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(0)); + } + + // Install the IP stack on the UEs + internet.Install (ueNodes); + Ipv4InterfaceContainer ueIpIface; + ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs)); + // Assign IP address to UEs, and install applications + for (uint32_t u = 0; u < ueNodes.GetN (); ++u) + { + Ptr ueNode = ueNodes.Get (u); + // Set the default gateway for the UE + Ptr ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject ()); + ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1); + } + + // Activate an EPS Bearer (including Radio Bearer) between UEs and its eNB + lteHelper->ActivateEpsBearer (ueLteDevs, EpsBearer (EpsBearer::NGBR_VIDEO_TCP_DEFAULT), EpcTft::Default ()); + + + // Add X2 inteface + lteHelper->AddX2Interface (enbNodes); + + // X2-based Handover + lteHelper->HandoverRequest (Seconds (2.0), ueNodes.Get (0), enbNodes.Get (0), enbNodes.Get (1)); + + + Simulator::Stop(Seconds(simTime)); + Simulator::Run(); + + // GtkConfigStore config; + // config.ConfigureAttributes(); + + Simulator::Destroy(); + return 0; + +} diff --git a/src/lte/wscript b/src/lte/wscript index dec2ec974..00c9dd216 100644 --- a/src/lte/wscript +++ b/src/lte/wscript @@ -61,6 +61,9 @@ def build(bld): 'model/trace-fading-loss-model.cc', 'model/epc-enb-application.cc', 'model/epc-sgw-pgw-application.cc', + 'model/epc-x2-sap.cc', + 'model/epc-x2-header.cc', + 'model/epc-x2.cc', 'model/epc-tft.cc', 'model/epc-tft-classifier.cc', 'model/lte-mi-error-model.cc' @@ -157,6 +160,9 @@ def build(bld): 'model/epc-gtpu-header.h', 'model/epc-enb-application.h', 'model/epc-sgw-pgw-application.h', + 'model/epc-x2-sap.h', + 'model/epc-x2-header.h', + 'model/epc-x2.h', 'test/lte-test-downlink-sinr.h', 'test/lte-test-uplink-sinr.h', 'test/lte-test-link-adaptation.h',