To simulate Dynamic Routing projects utilizing NS2, we require concentrating on routing protocols, which actively change to modifications within in network topology, traffic conditions, or other environmental factors. Dynamic routing protocols endlessly update their routing tables rely on the network conditions, like link failures or congestion. Famous dynamic routing protocols are supported by NS2 that contain AODV, DSR, and OLSR. Contact phdprime.com, and we assist you in achieving the best results at every step of your project.
We will guide you through set of steps for simulating dynamic routing in NS2.
Steps to Simulate Dynamic Routing in NS2
- Set Up NS2 Environment
Make sure NS2 is installed and working on the machine. We can verify this by executing the below command:
ns
If NS2 is properly installed then it will begin the NS2 shell.
- Understanding Dynamic Routing
Dynamic routing protocols automatically find and maintain routes by occasionally updating the routing tables. Instances of dynamic routing protocols contain:
- AODV (Ad hoc On-Demand Distance Vector)
- DSR (Dynamic Source Routing)
- OLSR (Optimized Link State Routing)
These protocols change to network topology modifications in real time that creating them ideal for mobile and wireless networks.
- Configure Dynamic Routing in NS2
We can set up dynamic routing protocols like AODV, DSR, or OLSR in NS2. The following is an instance TCL script utilizing AODV as the dynamic routing protocol.
- Writing a TCL Script
Below is a simple TCL script to replicate a network with dynamic routing utilizing the AODV protocol:
# Create a simulator object
set ns [new Simulator]
# Open trace and NAM output files
set tracefile [open out.tr w]
set namfile [open out.nam w]
$ns trace-all $tracefile
$ns namtrace-all $namfile
# Create a network topology
set topo [new Topography]
$topo load_flatgrid 500 500
# Define the number of nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Create duplex links between nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 15ms DropTail
$ns duplex-link $n2 $n3 512Kb 20ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
# Set AODV as the dynamic routing protocol
$ns rtproto AODV
# Set traffic between nodes
# Create a UDP agent and attach it to node n0
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
# Create a Null agent and attach it to node n4
set null0 [new Agent/Null]
$ns attach-agent $n4 $null0
# Create a traffic generator (CBR) and attach it to the UDP agent
set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 512
$cbr set interval_ 0.005
$cbr attach-agent $udp0
# Connect the UDP agent to the Null agent (source -> destination)
$ns connect $udp0 $null0
# Schedule the CBR traffic
$ns at 1.0 “$cbr start”
$ns at 4.5 “$cbr stop”
$ns at 5.0 “finish”
# Define the finish procedure
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
# Run the simulation
$ns run
- Explanation of the Script
- Routing Protocol: The script sets AODV as the routing protocol with $ns rtproto AODV. It is an on-demand dynamic routing protocol.
- Network Topology: The script describes a basic network topology with five nodes are attached via duplex links with changing bandwidth and delay.
- Traffic: A UDP agent is connected to n0, and traffic is transmitted from node n0 to node n4. A Constant Bit Rate (CBR) application is utilized to generate traffic.
- Simulate Network Dynamics (Link Failures or Changes)
To replicate dynamic behaviour like link failures or topology changes, we can change the network in the course of the simulation utilizing NS2’s RTModel. Here’s how to replicate a link failure:
# Schedule a link failure between n1 and n2 at 2.5 seconds
$ns rtmodel-at 2.5 down $n1 $n2
# Restore the link at 4.0 seconds
$ns rtmodel-at 4.0 up $n1 $n2
It will force the routing protocol to actively find a new path when the link among the node n1 and n2 goes down and fine-tune when it is restored.
- Running the Simulation
To execute the simulation, we can save the script as dynamic_routing.tcl and run the following command:
ns dynamic_routing.tcl
- Analyzing the Results
The simulation will make two files:
- Trace File (out.tr): Encompasses all events relevant to packet transmission, routing updates, link changes, and so on.
- NAM File (out.nam): A file for network visualization.
We can open the NAM file to envision the network behaviour and dynamic routing decisions:
nam out.nam
- Modifying the Script for More Complex Scenarios
We can expand the script to make more complex dynamic scenarios:
- Insert more nodes to replicate a larger dynamic network.
- Increase mobility: Launch mobile nodes by utilizing the mobility models are supported in NS2.
- Change the routing protocol: We can switch among AODV, DSR, or OLSR to monitor the performance of diverse dynamic routing protocols.
Example to use DSR:
$ns rtproto DSR
- Collecting and Analyzing Metrics
We can examine the performance of the dynamic routing protocol by extracting key parameters from the trace file, like:
- Packet Delivery Ratio (PDR): Percentage of effectively delivered packets.
- End-to-End Delay: The average time it takes for packets to travel from origin to destination.
- Routing Overhead: The amount of control packets are made by the dynamic routing protocol.
We can be used awk or grep commands to analyse the trace file and gather information. For instance:
grep “^r” out.tr | wc -l # Count the number of received packets
- Performance Evaluation
Calculate the performance of the dynamic routing simulation by changing metrics like:
- Node mobility: We can utilize mobile nodes to replicate real-world scenarios in mobile ad-hoc networks (MANETs).
- Network size: Maximizes the amount of nodes to experiment the scalability of the dynamic routing protocol.
- Traffic load: Alter the traffic load by maximizing or minimizing the amount of traffic flows.
These projects focussed on how to simulate the Dynamic routing projects, which accumulate, analyse the parameters and measure its performance through the simulation strategy within NS2 tool. If you ask more details and deeper analysis regarding these projects, we will be surely sent it too.