How to Start GPSR Protocol Project Using NS2

To stimulate a start a GPSR (Greedy Perimeter Stateless Routing) protocol project in NS2, follow these structured steps. GPSR is a generally used for position-based routing protocol in wireless ad-hoc networks such as MANETs or VANETs.

Steps to Start GPSR Protocol Project Using NS2

  1. Set up NS2 Environment

Make sure NS2 is installed and functioning correctly.

  • Install NS2:

sudo apt-get update

sudo apt-get install ns2

  • Verify Installation: Run:

ns

If successful, the NS2 interpreter will appear (%).

  1. Add GPSR Support to NS2

GPSR is not included through default in NS2. To add it:

  1. Download GPSR Patch:
    • GPSR patch files for NS2 are possible in repositories like:
      • MIT GPSR Extension for NS2
    • Download the patch for sample gpsr-patch.diff.
  2. Patch NS2:
    • Start the NS2 installation directory:

cd ns-allinone-2.35/ns-2.35

    • Execute the GPSR patch:

patch -p1 < /path/to/gpsr-patch.diff

  1. Recompile NS2:

./configure

make

    • It assures there are no errors in the recompilation process.
  1. Verify GPSR Installation:
    • Envision for the Agent/GPSR it helps installation for NS2 tool.
  1. Understand GPSR Protocol Components
  • Greedy Forwarding: Transmit the data for node closest geographically to the destination.
  • Perimeter Routing:  Intended for find the next hop after greedy used for forwarding fails.
  1. Write a TCL Simulation Script for GPSR

Here is an sample of a simple GPSR simulation script in NS2.

TCL Script for GPSR in NS2:

# Initialize the Simulator

set ns [new Simulator]

# Define output files

set nf [open gpsr-output.nam w]

$ns namtrace-all $nf

set tr [open gpsr-output.tr w]

$ns trace-all $tr

# Define nodes

set n(0) [$ns node]

set n(1) [$ns node]

set n(2) [$ns node]

set n(3) [$ns node]

# Setup network topology

$ns duplex-link $n(0) $n(1) 2Mb 10ms DropTail

$ns duplex-link $n(1) $n(2) 2Mb 10ms DropTail

$ns duplex-link $n(2) $n(3) 2Mb 10ms DropTail

# Enable GPSR protocol

Agent/GPSR set position_update_interval_ 0.1

$ns rtproto GPSR

# Define Traffic Source

set udp [new Agent/UDP]

$ns attach-agent $n(0) $udp

set null [new Agent/Null]

$ns attach-agent $n(3) $null

$ns connect $udp $null

# Define Application Traffic (CBR)

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set rate_ 1Mbps

# Start Traffic

$ns at 0.5 “$cbr start”

$ns at 4.5 “$cbr stop”

# Finish Simulation

$ns at 5.0 “finish”

proc finish {} {

global ns nf tr

$ns flush-trace

close $nf

close $tr

exec nam gpsr-output.nam &

exit 0

}

# Run the simulation

$ns run

  1. Run the Simulation
  1. Store the script as gpsr_simulation.tcl.
  2. The NS2 are process for command:

ns gpsr_simulation.tcl

  1. Outputs:
    • NAM File (gpsr-output.nam): Envision for the packet flow and forwarding the GPSR decisions.
    • Trace File (gpsr-output.tr): Logs all events for analysis.
  1. Analyze the Simulation Results

Key Metrics to Analyze:

  1. Packet Delivery Ratio (PDR): Calculate on how many packets are achieved reach the destination.

awk ‘{if($1==”r” && $4==”cbr”) rec++} END {print “Packet Delivery Ratio:”, rec}’ gpsr-output.tr

  1. End-to-End Delay:  It takes duration for calculate the packet we traverse in the network.
  2. Routing Overhead: Examine the routing overhead for control packets the created for GPSR operation.
  1. Enhance Your GPSR Project
  1. Add Mobility Models:
    • Use the models Random Waypoint Mobility for replicate the node actions:

set god_ [God instance]

$ns at 0.0 “$n(0) setdest 100 200 10”

  1. Simulate a Larger Topology:
    • The network topology are enhance the number of nodes and connection.
  2. Traffic Types:
    • It improves the TCP, FTP, or several UDP streams.
  3. Performance Comparison:
    • Associate the GPSR through reactive protocols such as AODV or DSR.
  4. Scalability Analysis:
    • Estimate the different numbers of nodes and congestion loads for GPSR’s performance.
  1. Tools for Results Analysis
  • The tool is NAM (Network Animator) for view the test of routing.
  • Use the tool AWK scripts or Python scripts for study the trace files in performance of parameter metrics.
  • The Plot outcomes using this tool Matplotlib or Gnuplot for instance end-to-end delay vs number of nodes.

Example Project Ideas:

  1. Performance Analysis of GPSR in MANET:
    • Associate with GPSR by AODV and DSR in mobile environments for performance analysis of GPSR.
  2. Energy-Efficient GPSR:
    • Alter are execute for GPSR it decrease the energy usage.
  3. Scalability of GPSR:
    • GPSR validate in the large-scale networks.
  4. QoS-aware GPSR:
    • Quality of Service improved the parameter metrics such as delay and bandwidth.

Through the entire process, you can acquire the simulation and execution process regarding the Greedy Perimeter Stateless Routing project offered in it using ns2 tool. We will plan to offer the more information regarding the Greedy Perimeter Stateless Routing in another manual.