How to Simulate Distributed Routing Projects Using NS2

To simulate distributed routing projects in NS2, we require executing a routing protocol, which utilizes distributed routing methods in which each node creates local decisions depends on information from its neighbours without based on a centralized entity. Protocols such as Distance Vector Routing (DVR) and Link State Routing (LSR) are instances of distributed routing protocols.

Here’s a series of steps on how to simulate a distributed routing project in NS2:

Steps to Simulate Distributed Routing Projects in NS2

  1. Install NS2

Make certain NS2 is installed on the computer. If not, we can download it from the NS2 Official Website and then we follow the installation guidelines for the operating system.

  1. Select a Distributed Routing Protocol

General distributed routing protocols contain:

  • AODV (Ad hoc On-Demand Distance Vector): A reactive distributed routing protocol.
  • DSR (Dynamic Source Routing): A reactive distributed routing protocol.
  • OSPF (Open Shortest Path First): A link-state distributed routing protocol.
  • Bellman-Ford-based DVR: Uses distributed routing updates to compute the paths.

For this instance, we will be used AODV as it is a distributed on-demand protocol in which each node communicates locally with neighbours.

  1. Create a TCL Script for Distributed Routing

We will require making a TCL script, which describes the network topology, sets up the distributed routing protocol, and replicate traffic among the nodes.

Example TCL Script for AODV Distributed Routing:

# Create a simulator object

set ns [new Simulator]

# Define trace and nam files for analysis and visualization

set tracefile [open “distributed_routing_trace.tr” w]

set namfile [open “distributed_routing_simulation.nam” w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Create network topology and configure wireless settings

set topo [new Topography]

$topo load_flatgrid 500 500

# Configure wireless nodes with AODV (a distributed routing protocol)

create-god 10  # Define the number of nodes

$ns node-config -adhocRouting AODV \

-llType LL \

-macType Mac/802_11 \

-ifqType Queue/DropTail/PriQueue \

-ifqLen 50 \

-antType Antenna/OmniAntenna \

-propType Propagation/TwoRayGround \

-phyType Phy/WirelessPhy \

-channelType Channel/WirelessChannel \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-movementTrace OFF

# Create the wireless nodes

for {set i 0} {$i < 10} {incr i} {

set node_($i) [$ns node]

$node_($i) random-motion 0  ;# Disable random mobility

}

# Manually set node positions (optional)

$node_(0) set X_ 50

$node_(0) set Y_ 50

$node_(0) set Z_ 0

$node_(1) set X_ 100

$node_(1) set Y_ 100

$node_(1) set Z_ 0

# Continue setting positions for other nodes…

# Define a UDP agent and attach it to node 0 (source)

set udp0 [new Agent/UDP]

$ns attach-agent $node_(0) $udp0

# Define a CBR (Constant Bit Rate) traffic generator for the UDP agent

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 0.5Mb

$cbr0 attach-agent $udp0

# Attach a UDP sink agent to node 9 (destination)

set udp1 [new Agent/UDP]

$ns attach-agent $node_(9) $udp1

# Connect the source and the destination agents

$ns connect $udp0 $udp1

# Schedule the traffic flow

$ns at 1.0 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

# Define the finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exit 0

}

# Schedule the end of the simulation at 5 seconds

$ns at 5.0 “finish”

# Run the simulation

$ns run

  1. Run the Simulation

We can save this script as distributed_routing_simulation.tcl, and then run it using NS2 with the below command:

ns distributed_routing_simulation.tcl

  1. Visualize the Simulation

We can open the generated NAM file to envision the network and the distributed routing decisions:

nam distributed_routing_simulation.nam

  1. Analyze the Trace File

The trace file (distributed_routing_trace.tr) includes information regarding the packet transmissions and routing decisions created by the AODV protocol. We can investigate this file to learn:

  • How the routing protocol distributes routing decisions over the nodes.
  • Packet delivery ratio and end-to-end delay.
  • Route discovery and maintenance.
  1. Modify the Simulation
  • Node Mobility: Allow node mobility to monitor how distributed routing protocols manage the dynamic topologies.
  • Different Traffic Patterns: Launch additional traffic sources and destinations to replicate real-world scenarios.
  • Scalability: Maximizes the amount of nodes and focus on how distributed routing protocols scale within larger networks.

Optional Enhancements:

  • Link Failure: Launch link failures by disabling links after a particular time and observe how the distributed routing protocol adjusts.
  • Energy-Efficient Distributed Routing: Replicate protocols, which prioritize energy consumption as well as distributed routing.

Utilizing NS2 tool, we executed the complete simulation techniques with example coding for implementing routing protocol that uses distributed routing methods. More extensive details can be offered if necessary.

phdprime.com provide guidance on protocols like Distance Vector Routing (DVR) and Link State Routing (LSR) relevant to your project. For assistance with any Distributed Routing Projects simulation, share your project details with us, and we will deliver optimal results. To conduct network comparison analysis, connect with phdprime.com for a complete explanation.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2