How to Implement Proactive Protocols in NS2

To implement proactive routing protocols in Network Simulator 2 (NS2) has essential to configure the simulation script that utilizes one of the proactive protocols obtainable in NS2.The Proactive routing protocols, otherwise known as table-driven protocols, sustain novel lists of destinations and their routes by occasionally allocating routing tables throughout the network. The frequent sample of proactive protocol contains Optimized Link State Routing (OLSR) and Destination-Sequenced Distance Vector (DSDV). The given below is the procedure to implement the proactive protocols in ns2:

Implementing Proactive Protocols in NS2

Here’s we can see on how to implement a proactive protocol such as DSDV or OLSR in NS2:

Step 1: Install NS2

Make certain that NS2 is installed on the system.

Step 2: Choose a Proactive Protocol

NS2 supports various proactive routing protocols that has DSDV and OLSR. Select the one we want to implement.

Step 3: Create a Simulation Script

We need to generate a Tcl script to configure the network simulation with the certain proactive routing protocol.

Example: Implementing DSDV in NS2

  1. Create a new Tcl script: Open a text editor and create a new file, for instance, dsdv_example.tcl.
  2. Set up the simulation environment: describe the simulator, configure the network topology, and setup the metrics that particular to 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)     DSDV                       ;# 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

  1. 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)

  1. 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

  1. 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 4: Run the Simulation

  1. Save the Tcl script (dsdv_example.tcl).
  2. Open a terminal and navigate to the directory in which we saved the Tcl script.
  3. Execute the simulation using the following command:

ns dsdv_example.tcl

This command will make a trace files and optionally a network animation file (if enabled in script).

Step 5: Analyze the Results

We can use tools such as awk, perl, or other scripting languages to process the trace files produced by NS2 to evaluate the performance of the DSDV protocol.

Step 6: Visualize the Results (Optional)

If we have allowed the network animator (NAM) in script, we can visualize the simulation:

nam dsdv_example.nam

This will open the NAM window, in which we can see the network topology and the behaviour of the DSDV protocol during the simulation.

Additional Considerations:

  • Mobility: To mimic a dynamic network, we can add node movement patterns or use mobility models.
  • Traffic Types: Test with various types of traffic like TCP, FTP to see how the proactive protocol performs in numerous conditions.
  • Performance Metrics: gather the parameters such as packet delivery ratio, end-to-end delay, and routing overhead to assess the performance of the proactive protocol.

Example: Implementing OLSR in NS2

We need to follow a related techniques to execute an OLSR by configuring the set val(rp) OLSR in the configuration.

In the end of the manual, we clearly showed the elaborate details about how to execute and implement the proactive protocols in ns2 simulation tool. Additional specific details will be provided regarding proactive protocols.

Discover top-notch research ideas in this field through our expertise. We provide guidance on implementing the most effective Proactive Protocols in NS2, ensuring you receive timely results. Reach out to us for support.