To simulate the LTE (Long-Term Evolution) projects within NS3 (Network Simulator 3), which permits to model and examine the performance of LTE networks, containing features such as radio access, mobility, and core network interactions. NS3 offers dedicated modules for LTE simulation, allowing complete analysis of numerous LTE scenarios. We provide complete procedure to help us configure and replicate LTE projects in NS3:
Steps to Simulate LTE Projects in NS3
- Prerequisites
Before diving into LTE simulation, make sure that we have the following:
- Operating System: NS3 is mainly enhanced for Linux (Ubuntu is recommended). Even though it’s possible to run NS3 on Windows or macOS using virtualization (e.g., VirtualBox) or the Windows Subsystem for Linux (WSL), Linux offers the most straightforward setup.
- Development Tools: Make certain we have important development tools installed.
sudo apt update
sudo apt install build-essential autoconf automake libxmu-dev gcc g++ python3
- NS3 Installation: Install the up-to-date stable version of NS3. Even though the ns-3-dev repository includes the recent development version, we may prefer a stable release for consistency.
# Download the latest stable release (replace ‘ns-allinone-3.xx’ with the latest version)
wget https://www.nsnam.org/release/ns-allinone-3.xx.tar.bz2
tar -xjf ns-allinone-3.xx.tar.bz2
cd ns-allinone-3.xx/ns-3.xx/
# Configure and build NS3 with LTE support
./waf configure –enable-examples –enable-tests –with-lte
./waf build
Note: Substitute 3.xx with the latest version number (e.g., 3.36). As of my knowledge cutoff in September 2021, the latest version was NS3.36, but please verify the official NS3 website for the latest release.
- Understanding LTE Modules in NS3
NS3’s LTE module is split into numerous sub-modules to model various features of LTE networks:
- LteModule: Consists of models for the LTE radio access network, that containing eNodeB (base stations) and UEs (User Equipments).
- LteHelper: A helper class to simplify the creation and set up of LTE networks.
- EpcHelper: Models the Evolved Packet Core (EPC) that contains components such as the Mobility Management Entity (MME), Serving Gateway (SGW), and Packet Data Network Gateway (PGW).
- UeSpectrumPhy & EnbSpectrumPhy: Physical layer models for UEs and eNodeBs, correspondingly.
Knowing these components is crucial for effectively replicating LTE networks.
- Basic LTE Simulation Setup
The following is a step-by-step approach to configuring a simple LTE simulation in NS3. This example contains:
- One eNodeB
- Multiple UEs
- An EPC for core network functionalities
- UDP Traffic Generation
3.1. Include Necessary Headers
Initially, we containing the needed NS3 modules in the simulation script.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/lte-module.h”
#include “ns3/internet-module.h”
#include “ns3/applications-module.h”
3.2. Using the NS3 Namespace
using namespace ns3;
3.3. Main Function Structure
Below is a simiple structure of the main function for LTE simulation:
int main(int argc, char *argv[])
{
// Enable logging (optional)
// LogComponentEnable(“LteHelper”, LOG_LEVEL_INFO);
// Default simulation parameters
uint16_t numberOfUes = 10;
double simTime = 10.0; // seconds
// Parse command line arguments (optional)
CommandLine cmd;
cmd.AddValue(“numberOfUes”, “Number of UEs”, numberOfUes);
cmd.AddValue(“simTime”, “Simulation time in seconds”, simTime);
cmd.Parse(argc, argv);
// Create the LTE helper and EPC helper
Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
lteHelper->SetEpcHelper(epcHelper);
// Create a single remote host
Ptr<Node> remoteHost = CreateObject<Node>();
InternetStackHelper internet;
internet.Install(remoteHost);
// Create the internet connection between the EPC and the remote host
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute(“DataRate”, StringValue(“100Gb/s”));
p2ph.SetChannelAttribute(“Delay”, StringValue(“10ms”));
NetDeviceContainer internetDevices = p2ph.Install(epcHelper->GetPgwNode(), remoteHost);
// Assign IP addresses
Ipv4AddressHelper ipv4;
ipv4.SetBase(“1.0.0.0”, “255.0.0.0”);
Ipv4InterfaceContainer internetIpIfaces = ipv4.Assign(internetDevices);
// Assign IP address to the remote host
Ptr<Ipv4> ipv4RemoteHost = remoteHost->GetObject<Ipv4>();
Ipv4Address remoteHostAddr = ipv4RemoteHost->GetAddress(1, 0).GetLocal();
// Create eNodeB and UE nodes
NodeContainer enbNodes;
enbNodes.Create(1);
NodeContainer ueNodes;
ueNodes.Create(numberOfUes);
// Install Mobility Model for eNodeB and UEs
MobilityHelper mobility;
// eNodeB mobility
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(enbNodes);
Ptr<MobilityModel> mob = enbNodes.Get(0)->GetObject<MobilityModel>();
mob->SetPosition(Vector(0, 0, 0)); // Position at origin
// UE mobility
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(ueNodes);
for (uint16_t i = 0; i < numberOfUes; ++i)
{
Ptr<MobilityModel> ueMob = ueNodes.Get(i)->GetObject<MobilityModel>();
ueMob->SetPosition(Vector(100 + i * 10, 0, 0)); // Spread UEs along x-axis
}
// Install LTE Devices to the nodes
NetDeviceContainer enbDevs = lteHelper->InstallEnbDevice(enbNodes);
NetDeviceContainer ueDevs = lteHelper->InstallUeDevice(ueNodes);
// Install the IP stack on UEs
internet.Install(ueNodes);
// Assign IP addresses to UEs
Ipv4InterfaceContainer ueIpIfaces = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueDevs));
// Attach UEs to the eNodeB
for (uint32_t i = 0; i < ueNodes.GetN(); ++i)
{
lteHelper->Attach(ueDevs.Get(i), enbDevs.Get(0));
}
// Install and start applications on UEs and remote host
uint16_t port = 9; // Discard port
// Create a UDP server on the remote host
UdpServerHelper udpServer(port);
ApplicationContainer serverApp = udpServer.Install(remoteHost);
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(simTime));
// Create a UDP client on each UE
UdpClientHelper udpClient(remoteHostAddr, port);
udpClient.SetAttribute(“MaxPackets”, UintegerValue(1000000));
udpClient.SetAttribute(“Interval”, TimeValue(Seconds(0.001)));
udpClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps;
for (uint32_t i = 0; i < ueNodes.GetN(); ++i)
{
clientApps.Add(udpClient.Install(ueNodes.Get(i)));
}
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(simTime));
// Enable PCAP tracing (optional)
lteHelper->EnablePcapAll(“lte-simulation”);
// Run the simulation
Simulator::Stop(Seconds(simTime));
Simulator::Run();
Simulator::Destroy();
return 0;
}
3.4. Explanation of the Code
- Logging (Optional):
// LogComponentEnable(“LteHelper”, LOG_LEVEL_INFO);
Allow logging for debugging and observing purposes. Uncomment and adapt the recording level as required.
- Simulation Parameters:
- numberOfUes: Number of User Equipments (UEs) to replicate.
- simTime: Total simulation time in seconds.
- LTE and EPC Helpers:
Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
lteHelper->SetEpcHelper(epcHelper);
-
- LteHelper: Facilitates LTE network creation.
- EpcHelper: Models the core network. PointToPointEpcHelper delivers a basic EPC model using point-to-point links.
- Remote Host Setup:
- A unique remote host is made and connected to the PGW (Packet Gateway) through a high-speed point-to-point link.
- Mobility Models:
- eNodeB: Positioned at the origin with a ConstantPositionMobilityModel (static).
- UEs: Spread along the x-axis with a ConstantPositionMobilityModel. For more dynamic simulations, deliberate using mobile mobility models such as RandomWalk2dMobilityModel or ConstantVelocityMobilityModel.
- Device Installation:
- eNodeB Devices: Installed on eNodeB nodes.
- UE Devices: Installed on UE nodes.
- IP Stack and Address Assignment:
- The internet stack is installed on UEs.
- IP addresses are allocated to UEs by the EPC.
- UE Attachment:
- Each UE is attached to the eNodeB using the Attach method, establishing their connection to the network.
- Application Setup:
- UDP Server: Installed on the remote host to receive packets.
- UDP Clients: Installed on each UE to transmit packets to the remote host.
- Tracing (Optional):
lteHelper->EnablePcapAll(“lte-simulation”);
Allows PCAP tracing for all LTE devices, permitting to capture and examine packet flows using tools such as Wireshark.
- Simulation Execution:
- The simulation runs until the specified simTime and then cleans up.
- Enhancing the Simulation
The simple simulation above offers a foundation. We can be improved it further rely on project requirements.
4.1. Mobility Models
To replicate realistic scenarios in which UEs are moving, substitute the ConstantPositionMobilityModel with dynamic mobility models.
Example: Random Waypoint Mobility
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=20.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”),
“PositionAllocator”, StringValue(“ns3::RandomRectanglePositionAllocator”));
mobility.Install(ueNodes);
4.2. Multiple eNodeBs and Handover
For replications containing numerous eNodeBs and UE mobility leading to handovers:
- Create Multiple eNodeBs:
NodeContainer enbNodes;
enbNodes.Create(3); // For example, 3 eNodeBs
// Position eNodeBs at different locations
- Configure Handover Parameters: NS3 manages handovers automatically according to the UE mobility and signal strength. Make certain that mobility models are place UEs within range of numerous eNodeBs in the course of the simulation.
4.3. Different Traffic Models
Rather than using UDP traffic, we can replicate numerous application types:
- TCP Traffic: For mimicking web browsing, file transfers, and so on.
// Install BulkSendApplication on UEs
BulkSendHelper source(“ns3::TcpSocketFactory”, InetSocketAddress(remoteHostAddr, port));
source.SetAttribute(“MaxBytes”, UintegerValue(0)); // 0 means unlimited
ApplicationContainer sourceApps = source.Install(ueNodes);
sourceApps.Start(Seconds(2.0));
sourceApps.Stop(Seconds(simTime));
// Install PacketSink on the remote host
PacketSinkHelper sink(“ns3::TcpSocketFactory”, InetSocketAddress(Ipv4Address::GetAny(), port));
ApplicationContainer sinkApp = sink.Install(remoteHost);
sinkApp.Start(Seconds(1.0));
sinkApp.Stop(Seconds(simTime));
- Video Streaming: Using applications such as OnOffApplication to replicate video streaming with particular traffic patterns.
4.4. Quality of Service (QoS) Configuration
NS3 LTE models support numerous QoS mechanisms. We can describe various bearers with particular QoS parameters.
Example: Creating a Best-Effort Bearer
enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
EpsBearer bearer(q);
lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
4.5. Advanced Tracing and Monitoring
To investigate the network performance parameters:
- Flow Monitor:
#include “ns3/flow-monitor-module.h”
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
// After Simulator::Run()
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmon.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
for (auto const &flow : stats)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(flow.first);
std::cout << “Flow ” << flow.first << ” (” << t.sourceAddress << ” -> ” << t.destinationAddress << “)\n”;
std::cout << ” Tx Bytes: ” << flow.second.txBytes << “\n”;
std::cout << ” Rx Bytes: ” << flow.second.rxBytes << “\n”;
std::cout << ” Throughput: ” << flow.second.rxBytes * 8.0 / (flow.second.timeLastRxPacket.GetSeconds() – flow.second.timeFirstTxPacket.GetSeconds()) / 1000000 << ” Mbps\n”;
}
- Energy Consumption: NS3 offers models to eplicate the energy consumption of devices that can be essential for battery-powered UEs.
- NetAnim Visualization:
#include “ns3/netanim-module.h”
AnimationInterface anim(“lte-animation.xml”);
We can use NetAnim to visualize node movements, packet flows, and other events.
4.6. Integrating with Other Modules
NS3 enables an integration with other network modules for comprehensive simulations:
- WiFi: Replicate the hybrid LTE/WiFi networks.
- MEC (Multi-access Edge Computing): Model edge computing situations.
- IoT: Integrate LTE with IoT devices for IoT-LTE simulations.
- Running the Simulation
5.1. Compiling the Simulation Script
- Save the Script: We can save the LTE simulation script in the scratch/ directory of the NS3 installation, for instance scratch/lte-simulation.cc.
- Build NS3:
./waf build
Note: If you have appended new modules or dependencies, make sure they are appropriately referenced.
5.2. Executing the Simulation
We run thesimulation using the waf command:
./waf –run scratch/lte-simulation
5.3. Viewing Results
- Console Output: Any std::cout statements or NS3 recording will appear in the terminal.
- PCAP Files: If PCAP tracing is allowed then .pcap files will be produced (e.g., lte-simulation-enb0-0-0.pcap). We can use Wireshark to estimate these files.
- Flow Monitor Reports: If using the Flow Monitor then the output metrics will be shown in the console or can be saved to XML files for advance analysis.
- NetAnim: If animation is permitted then open the generated .xml file in NetAnim to envision the simulation.
./waf –run scratch/lte-simulation –vis
Otherwise, we open the lte-animation.xml in NetAnim:
netanim lte-animation.xml
- Advanced LTE Simulation Features
6.1. Carrier Aggregation and MIMO
NS3 LTE modules support furthered aspects such as carrier aggregation and Multiple Input Multiple Output (MIMO). Set up these aspects using suitable helper classes and attributes.
Example: Enabling MIMO
lteHelper->SetAttribute(“MimoMode”, EnumValue(LteHelper::MIMO4));
6.2. Different Spectrum Allocations
Replicate numerous spectrum allocations by adapting the bandwidth and frequency settings.
lteHelper->SetSchedulerType(“ns3::PfFfMacScheduler”); // Proportional Fair Scheduler
lteHelper->SetEnbDeviceAttribute(“DlBandwidth”, UintegerValue(50)); // 50 PRBs
lteHelper->SetEnbDeviceAttribute(“UlBandwidth”, UintegerValue(50)); // 50 PRBs
6.3. Interference and Propagation Models
Integrate realistic propagation models to replicate the interference and signal degradation.
Ptr<LteSpectrumPhy> enbPhy = enbDevs.Get(0)->GetObject<LteSpectrumPhy>();
enbPhy->SetAttribute(“NoiseFigure”, DoubleValue(9.0));
6.4. Heterogeneous Networks (HetNets)
Mimic HetNets by integrating macro eNodeBs with small cells (e.g., picocells or femtocells).
- Example: Complete LTE Simulation Script
The following is a comprehensive instance script incorporating numerous concepts discussed:
// File: scratch/lte-simulation.cc
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-module.h”
#include “ns3/lte-module.h”
#include “ns3/internet-module.h”
#include “ns3/applications-module.h”
#include “ns3/flow-monitor-module.h”
#include “ns3/netanim-module.h”
using namespace ns3;
int main(int argc, char *argv[])
{
// Enable logging
LogComponentEnable(“LteHelper”, LOG_LEVEL_INFO);
LogComponentEnable(“UdpClient”, LOG_LEVEL_INFO);
LogComponentEnable(“UdpServer”, LOG_LEVEL_INFO);
// Simulation parameters
uint16_t numberOfUes = 10;
double simTime = 10.0; // seconds
// Parse command line arguments
CommandLine cmd;
cmd.AddValue(“numberOfUes”, “Number of UEs”, numberOfUes);
cmd.AddValue(“simTime”, “Simulation time in seconds”, simTime);
cmd.Parse(argc, argv);
// Create LTE and EPC helpers
Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
lteHelper->SetEpcHelper(epcHelper);
// Create remote host
Ptr<Node> remoteHost = CreateObject<Node>();
InternetStackHelper internet;
internet.Install(remoteHost);
// Create internet connection
PointToPointHelper p2ph;
p2ph.SetDeviceAttribute(“DataRate”, StringValue(“100Gb/s”));
p2ph.SetChannelAttribute(“Delay”, StringValue(“10ms”));
NetDeviceContainer internetDevices = p2ph.Install(epcHelper->GetPgwNode(), remoteHost);
// Assign IP addresses
Ipv4AddressHelper ipv4;
ipv4.SetBase(“1.0.0.0”, “255.0.0.0”);
Ipv4InterfaceContainer internetIpIfaces = ipv4.Assign(internetDevices);
// Get remote host’s IP address
Ptr<Ipv4> ipv4RemoteHost = remoteHost->GetObject<Ipv4>();
Ipv4Address remoteHostAddr = ipv4RemoteHost->GetAddress(1, 0).GetLocal();
// Create eNodeB and UE nodes
NodeContainer enbNodes;
enbNodes.Create(1);
NodeContainer ueNodes;
ueNodes.Create(numberOfUes);
// Install mobility model
MobilityHelper mobility;
// eNodeB mobility
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(enbNodes);
Ptr<MobilityModel> enbMob = enbNodes.Get(0)->GetObject<MobilityModel>();
enbMob->SetPosition(Vector(0, 0, 0)); // Position at origin
// UE mobility
mobility.SetMobilityModel(“ns3::RandomWalk2dMobilityModel”,
“Bounds”, RectangleValue(Rectangle(0, 500, 0, 500)));
mobility.Install(ueNodes);
// Install LTE Devices
NetDeviceContainer enbDevs = lteHelper->InstallEnbDevice(enbNodes);
NetDeviceContainer ueDevs = lteHelper->InstallUeDevice(ueNodes);
// Install the IP stack on UEs
internet.Install(ueNodes);
// Assign IP addresses to UEs
Ipv4InterfaceContainer ueIpIfaces = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueDevs));
// Attach UEs to the eNodeB
for (uint32_t i = 0; i < ueNodes.GetN(); ++i)
{
lteHelper->Attach(ueDevs.Get(i), enbDevs.Get(0));
}
// Install applications
uint16_t port = 9; // Discard port
// Create UDP server on remote host
UdpServerHelper udpServer(port);
ApplicationContainer serverApp = udpServer.Install(remoteHost);
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(simTime));
// Create UDP clients on UEs
UdpClientHelper udpClient(remoteHostAddr, port);
udpClient.SetAttribute(“MaxPackets”, UintegerValue(1000000));
udpClient.SetAttribute(“Interval”, TimeValue(Seconds(0.001)));
udpClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps;
for (uint32_t i = 0; i < ueNodes.GetN(); ++i)
{
clientApps.Add(udpClient.Install(ueNodes.Get(i)));
}
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(simTime));
// Enable PCAP tracing
lteHelper->EnablePcapAll(“lte-simulation”);
// Enable Flow Monitor
FlowMonitorHelper flowmonHelper;
Ptr<FlowMonitor> monitor = flowmonHelper.InstallAll();
// Enable NetAnim
AnimationInterface anim(“lte-animation.xml”);
// Run the simulation
Simulator::Stop(Seconds(simTime));
Simulator::Run();
// Flow Monitor statistics
monitor->CheckForLostPackets();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowmonHelper.GetClassifier());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();
for (auto const &flow : stats)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(flow.first);
std::cout << “Flow ” << flow.first << ” (” << t.sourceAddress << ” -> ” << t.destinationAddress << “)\n”;
std::cout << ” Tx Bytes: ” << flow.second.txBytes << “\n”;
std::cout << ” Rx Bytes: ” << flow.second.rxBytes << “\n”;
std::cout << ” Throughput: ” << flow.second.rxBytes * 8.0 / (flow.second.timeLastRxPacket.GetSeconds() – flow.second.timeFirstTxPacket.GetSeconds()) / 1000000 << ” Mbps\n”;
}
// Destroy the simulation
Simulator::Destroy();
return 0;
}
6.8. Running the Example Script
- Save the Script: We can save the above code as lte-simulation.cc in the scratch/ directory.
- Build NS3:
./waf build
- Run the Simulation:
./waf –run scratch/lte-simulation
- Visualize with NetAnim:
Here, we open the generated lte-animation.xml in NetAnim to observe the node movements and packet flows.
netanim lte-animation.xml
- Additional Resources
- NS3 LTE Module Documentation: Comprehensive documentation on LTE models and APIs.
NS3 LTE Documentation
- NS3 Tutorials: Step-by-step tutorials to acquire hands-on experience.
NS3 Tutorials
- Example Simulations: Review and change instance LTE simulations delivered in NS3.
ls examples/lte/
- NS3 Forum and Mailing Lists: Occupy with the NS3 community for support and discussions.
NS3 Forum
- Tips for Successful LTE Simulation
- Start Simple: Start with a simple simulation configure before adding complexity.
- Use Existing Examples: Leverage NS3’s instance scripts as templates.
- Enable Logging: Use NS3’s logging system to debug and know the simulation behaviour.
- Monitor Performance Metrics: Utilise Flow Monitor and other tools to estimate the throughput, latency, and packet loss.
- Validate with Real-World Data: Compare simulation outcomes with theoretical or empirical data to make certain exactness.
- Optimize Simulation Time: Large-scale simulations can be time-consuming. Enhance by limiting the number of UEs or simulation duration in the beginning.
- Explore Different Scenarios: Analyse numerous network configurations, mobility patterns, and traffic types to completely estimate LTE performance.
In this manual, we illustrated enormous informations about LTE projects including aspects such as radio access, mobility, and core network interactions. We demonstrated the comprehensive process to simulate and configure the LTE projects using NS3 tool. Moreover, we will present advanced details on this projects, if you required. If you’re looking to simulate LTE projects using the NS3 tool, consider reaching out to phdprime.com. We are dedicated to providing you with the best simulation results possible.