How to Simulate Proactive Protocols Projects Using NS2

To simulate proactive routing protocols using NS2 (Network Simulator 2), we follows same steps as other routing protocol simulations. Proactive routing protocols, such as OLSR (Optimized Link State Routing) and DSDV (Destination-Sequenced Distance-Vector Routing), continuously conserve updated routing tables for every node, make certain routes are always available when required.

Below is a structural method on how to simulate projects using proactive routing protocols in NS2, which concentrating on OLSR and DSDV:

Steps for Simulating Proactive Protocols in NS2

  1. Install NS2

Make sure we have NS2 installed. Unless, we install it using the below commands for Linux systems:

sudo apt-get install ns2

For Windows, we can use Cygwin or download a precompiled NS2 package.

  1. Choose a Proactive Routing Protocol

NS2 supports both OLSR and DSDV as built-in routing protocols. We can select one based on the project needs. Here, we will offer instance for both OLSR and DSDDV.

  1. Create a TCL Simulation Script

Example 1: Simulating OLSR in NS2

Here’s an instance of a TCL script to replicate the OLSR (Optimized Link State Routing) protocol:

# Define the simulator object

set ns [new Simulator]

# Open trace and NAM file to store simulation results and visualization

set tracefile [open olsr_proactive.tr w]

$ns trace-all $tracefile

set namfile [open olsr_proactive.nam w]

$ns namtrace-all $namfile

# Define the number of nodes, simulation time, and the routing protocol (OLSR)

set val(nn) 10               ;# Number of nodes

set val(stop) 50.0           ;# Simulation stop time

set val(routing) OLSR        ;# Use OLSR proactive routing protocol

# Define topology

set topo [new Topography]

$topo load_flatgrid 500 500

# Define network parameters

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

set val(ll)     LL                         ;# Link layer type

set val(ant)    Antenna/OmniAntenna        ;# Antenna model

set val(ifqlen) 50                         ;# Interface queue length

set val(x)      500                        ;# X dimension of topology

set val(y)      500                        ;# Y dimension of topology

# Create nodes and configure OLSR routing

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

}

# Set up the OLSR routing protocol

$ns rtproto $val(routing)

# Set node positions (You can add mobility models here)

$node_(0) set X_ 100.0

$node_(0) set Y_ 100.0

$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0

$node_(1) set Y_ 200.0

$node_(1) set Z_ 0.0

# (Continue for other nodes)

# Create UDP traffic between two nodes

set udp0 [new Agent/UDP]

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

set null0 [new Agent/Null]

$ns attach-agent $node_(1) $null0

$ns connect $udp0 $null0

# Setup a CBR (Constant Bit Rate) application over UDP

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.01

$cbr0 attach-agent $udp0

$ns at 1.0 “$cbr0 start”

$ns at 50.0 “$cbr0 stop”

# End the simulation

$ns at $val(stop) “finish”

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam olsr_proactive.nam &

exit 0

}

# Start the simulation

$ns run

Example 2: Simulating DSDV in NS2

Below is an example of how to simulate the DSDV (Destination-Sequenced Distance-Vector Routing) protocol in NS2:

# Define simulator object

set ns [new Simulator]

# Open trace file and NAM file

set tracefile [open dsdv_proactive.tr w]

$ns trace-all $tracefile

set namfile [open dsdv_proactive.nam w]

$ns namtrace-all $namfile

# Define parameters

set val(nn) 10                ;# Number of nodes

set val(stop) 50.0            ;# Simulation stop time

set val(routing) DSDV         ;# Use DSDV proactive routing protocol

# Define topology

set topo [new Topography]

$topo load_flatgrid 500 500

# Define network parameters

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

set val(ll)     LL                         ;# Link layer type

set val(ant)    Antenna/OmniAntenna        ;# Antenna model

set val(ifqlen) 50                         ;# Interface queue length

set val(x)      500                        ;# X dimension of topology

set val(y)      500                        ;# Y dimension of topology

# Create the nodes

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

}

# Set up DSDV routing protocol

$ns rtproto $val(routing)

# Set node positions (You can add mobility models here)

$node_(0) set X_ 100.0

$node_(0) set Y_ 100.0

$node_(0) set Z_ 0.0

$node_(1) set X_ 200.0

$node_(1) set Y_ 200.0

$node_(1) set Z_ 0.0

# (Continue setting up nodes…)

# Setup TCP traffic between two nodes

set tcp0 [new Agent/TCP]

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

set sink0 [new Agent/TCPSink]

$ns attach-agent $node_(1) $sink0

$ns connect $tcp0 $sink0

# Setup FTP over TCP

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 “$ftp0 start”

$ns at 50.0 “$ftp0 stop”

# End the simulation

$ns at $val(stop) “finish”

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam dsdv_proactive.nam &

exit 0

}

# Run the simulation

$ns run

  1. Running the Simulation

We can save the TCL script (e.g., olsr_simulation.tcl or dsdv_simulation.tcl), and then run it using the following command in the terminal:

ns olsr_simulation.tcl

or

ns dsdv_simulation.tcl

  1. Visualizing the Simulation

After running the simulation then a NAM (Network Animator) file will be made that permits to envision the network and routing behaviour. Utilize the following command to open the NAM visualization:

nam olsr_proactive.nam

or

nam dsdv_proactive.nam

We will observe the nodes and the packet exchange among them.

  1. Analysing the Trace File

The trace file (olsr_proactive.tr or dsdv_proactive.tr) involved detailed data regarding the packet flows, routing updates, packet drops, and other events. We can examine this file using AWK, Python, or custom scripts to calculate performance parameters like:

  • Packet Delivery Ratio
  • Throughput
  • End-to-End Delay
  • Routing Overhead
  • Packet Loss
  1. Customize the Simulation
  • Change Node Mobility: Insert mobility models to replicate nodes are moving actively in the network.
  • Increase Node Density: Change the amount of nodes and increase the network size.
  • Simulate Different Traffic Types: We can switch from UDP to TCP traffic, or experiment applications such as FTP, HTTP, and so on.
  • QoS Analysis: Execute and assess Quality of Service (QoS) in proactive protocols by changing packet size, bandwidth, delay, and queue types.

NS2 facilitated the simulation of the Proactive protocols projects that focuses on OLSR and DSDV, with additional insights available for a deeper exploration, if necessary.

We at phdprime.com are committed to being your trusted partner in guiding Proactive Protocols Projects simulations towards complete success.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2