How to Implement OLSR Protocol in NS2
To implement the Optimized Link State Routing (OLSR) protocol within NS2 (Network Simulator 2), which has want to make a simulation script that configures the network to use OLSR for routing. This simulation tool NS2 has built-in support for the protocol OLSR, thus we can use it directly by set up the suitable settings in the simulation script. We provided the step-by-step guide to implement it.
Step-by-Step Implementation:
Step 1: Install NS2
Make sure that NS2 is installed on the system. We can download it from the NS2 webpage and follow the installation instructions for the operating system.
Step 2: Create an OLSR Simulation Script
- Create a new Tcl script: Here, open a text editor and make a new file, for instance, olsr_example.tcl.
- Set up the simulation environment: Starting by describing the simulator, setting up the network topology, and configuring the metrics particular to the simulation.
# Create a simulator object
set ns [new Simulator]
# Define options for the simulation
set val(chan) Channel/WirelessChannel ;# Channel type
set val(prop) Propagation/TwoRayGround ;# Propagation model
set val(netif) Phy/WirelessPhy ;# Network interface type
set val(mac) Mac/802_11 ;# MAC type
set val(ifq) Queue/DropTail/PriQueue ;# Interface Queue type
set val(ll) LL ;# Link layer type
set val(ant) Antenna/OmniAntenna ;# Antenna type
set val(ifqlen) 50 ;# Max packet in ifq
set val(nn) 10 ;# Number of mobile nodes
set val(rp) OLSR ;# Routing Protocol
set val(x) 500 ;# X dimension of topography
set val(y) 500 ;# Y dimension of topography
set val(stop) 10.0 ;# Simulation time
# Initialize the topology object
set topo [new Topography]
$topo load_flatgrid $val(x) $val(y)
# Create the God object
create-god $val(nn)
# Configure the nodes
$ns node-config -adhocRouting $val(rp) \
-llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-antType $val(ant) \
-propType $val(prop) \
-phyType $val(netif) \
-channelType $val(chan) \
-topoInstance $topo \
-agentTrace ON \
-routerTrace ON \
-macTrace ON \
-movementTrace ON
- Create nodes and define mobility:
# Create mobile nodes
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) random-motion 0
}
# Define node movement (Optional for mobile nodes)
$node_(0) set X_ 50.0
$node_(0) set Y_ 50.0
$node_(0) set Z_ 0.0
$node_(1) set X_ 100.0
$node_(1) set Y_ 100.0
$node_(1) set Z_ 0.0
# (Add more movement patterns or use mobility models if needed)
- Setup traffic sources:
# Setup a UDP agent and attach it to node 0
set udp [new Agent/UDP]
$ns attach-agent $node_(0) $udp
# Setup CBR (Constant Bit Rate) application to generate traffic
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set interval_ 0.1
$cbr start
# Setup a Null agent (sink) on node 1
set null [new Agent/Null]
$ns attach-agent $node_(1) $null
# Connect the agents
$ns connect $udp $null
- Setup simulation end:
# Define simulation end time
$ns at $val(stop) “stop”
$ns at $val(stop) “$ns nam-end-wireless $val(stop)”
$ns at $val(stop) “exit 0”
proc stop {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
}
# Run the simulation
$ns run
Step 3: Run the Simulation
- We save the Tcl script such as olsr_example.tcl.
- Open a terminal and navigate to the directory in which we can saved the Tcl script.
- Run the simulation using the below command:
ns olsr_example.tcl
The above command will produce trace files and optionally a network animation file if permitted in the script.
Step 4: Analyse the Results
We can use tools such as awk, perl, or other scripting languages to process the trace files made by NS2 to evaluate the performance of the OLSR protocol.
Step 5: Visualize the Results (Optional)
If we have allowed the network animator (NAM) in the script, we can visualize the simulation:
nam olsr_example.nam
It will open the NAM window in which we can see the network topology and the behaviour of OLSR during the simulation.
Additional Considerations:
- Mobility: To mimic a more dynamic network, to deliberate appending the node movement patterns or using mobility models.
- Traffic Types: We can investigate with various kinds of traffic such as TCP, CBR, and FTP to observe how OLSR performs under several conditions.
- Metrics: We may need to gather and estimate the parameters like packet delivery ratio, end-to-end delay, and routing overhead to assess OLSR’s performance.
This procedure offered the step-by-step guide to help you implement the OLSR protocol from the basic set up to analysing the results. We will provide any details regarding this script, if needed.
Get performance analysis done for you. We provide top results for OLSR Protocol in NS2 implementation, get in touch with ns2project.com.