How to Start OLSR Protocol Projects Using NS3
To start Optimized Link State Routing (OLSR) protocol in NS3, for mobile ad hoc networks (MANETs) that is a proactive routing protocol which NS3 supports via the olsr-helper module. Below is a simple instruction to configuring an OLSR project in NS3.
Steps to Start OLSR Protocol Projects in NS3
- Install NS3
If we haven’t installed NS3 then configure with the below commands (assuming a Linux environment):
# Update system and install dependencies
sudo apt update
sudo apt install -y gcc g++ python3 python3-dev cmake libgsl-dev libsqlite3-dev
# Clone the NS-3 repository
git clone https://gitlab.com/nsnam/ns-3-dev.git ns-3
cd ns-3
# Configure and build NS-3
./ns3 configure –enable-examples –enable-tests
./ns3 build
- Create a New Script for OLSR Simulation
- We need to make a new file named olsr_simulation.cc in the scratch directory of NS3 and save it.
- We can utilize the below mentioned code as a basic configuration for an OLSR simulation:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/olsr-helper.h”
#include “ns3/mobility-module.h”
#include “ns3/wifi-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
int main(int argc, char *argv[]) {
// Enable OLSR logging
LogComponentEnable(“OlsrRoutingProtocol”, LOG_LEVEL_INFO);
// Create nodes for the MANET
NodeContainer nodes;
nodes.Create(10); // Example with 10 nodes
// Set up mobility for the nodes
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,
“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”),
“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”));
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=5.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”));
mobility.Install(nodes);
// Configure WiFi for ad hoc communication
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);
// Install Internet stack with OLSR routing
InternetStackHelper internet;
OlsrHelper olsr;
internet.SetRoutingHelper(olsr); // Set OLSR as the routing protocol
internet.Install(nodes);
// Assign IP addresses to the network interfaces
Ipv4AddressHelper ipv4;
ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = ipv4.Assign(devices);
// Set up a UDP echo server and client for testing OLSR
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(0));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(0), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(1));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(9));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
// Run the simulation
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
In this code:
-
- Nodes: For the ad hoc network, we make 10 nodes.
- Mobility Model: We configure a random waypoint mobility model replicating a mobile network environment normal of MANETs.
- WiFi Configuration: Utilize AdhocWifiMac, IEEE 802.11b standard is set up for ad hoc interaction.
- OLSR Routing: We want to use OlsrHelper, OLSR routing protocol is installed on each node.
- Application Setup: A UDP Echo server and client are set up to experiment the connectivity over the OLSR network.
- Build and Run the Simulation
- We can store olsr_simulation.cc within the scratch directory.
- Go to a terminal, pass through to NS3 directory, and then make the script:
./ns3 build
- Run the simulation:
./ns3 run scratch/olsr_simulation
- Analyze OLSR Results
The results will be indicated OLSR protocol activities that contain route table updates and packet forwarding. OLSR sustains and updates routes proactively thus we should observe the periodic updates within the routing tables. We can obtain additional in-depth logs, allow to record for OLSR:
LogComponentEnable(“OlsrRoutingProtocol”, LOG_LEVEL_ALL);
It will show data on route advertisements, neighbor discovery, and routing table maintenance.
Experimentation Ideas
To discover more including OLSR:
- Increase Node Count and Density: We need to insert more nodes and then modify the deployment area to experiment the OLSR scalability.
- Modify Mobility Models: Test with diverse mobility models, monitoring how OLSR adjusts to changing movement patterns.
- Measure Performance Metrics: We monitor the performance parameters such as packet delivery ratio, latency, and throughput to measure the performance of OLSR in various network conditions.
- Simulate Network Failures: In the network, detach some nodes to monitor how OLSR manage the dynamic modifications and link failures.
This guide focuses on instructing you the fundamental steps with example coding for OLSR Protocol projects simulation and execution in NS3 environment. We will also be added more advanced approaches for deeper understanding.
We conduct configuration and manage the replication of IP Protocol scenarios. To initiate OLSR Protocol projects utilizing NS3, it is essential to engage only experts for your tasks. Our team specializes in mobile ad hoc networks (MANETs). We at phdprojects.org comprises highly skilled and knowledgeable writers and developers dedicated to ensuring the timely completion of your projects.