How to Simulate Greedy Perimeter Stateless Routing Using NS2

To simulate Greedy Perimeter Stateless Routing (GPSR) using NS2, we will require executing or incorporating a GPSR module because NS2 doesn’t have a direct GPSR implementation. GPSR is a geographic routing protocol for wireless networks in which packets are sent depends on the place of nodes. In the greedy forwarding mode, packets are sent to the neighbour that nearby to the destination, even though the perimeter mode is utilized when greedy forwarding be unsuccessful (such as in the case of voids).

We will teach you through step-by-step process on how to simulate Greedy Perimeter Stateless Routing (GPSR) routing in NS2:

Steps to Simulate Greedy Perimeter Stateless Routing Projects in NS2

  1. Install NS2

Make sure that NS2 is installed. If not then we can download it from the NS2 Official Website and follow the installation steps for the operating system.

  1. Download and Integrate GPSR Module (if needed)

If we don’t have GPSR executed within NS2 then we can search for GPSR patches online or execute the protocol from scratch. We may discover community-contributed patches, which we can apply to NS2 for GPSR functionality.

  1. Create a TCL Script for GPSR Simulation

When GPSR is combined then we can make a TCL script to replicate the protocol. The script will describe the network topology, nodes, traffic patterns, and GPSR as the routing protocol.

Example TCL Script for GPSR Simulation:

# Create a simulator object

set ns [new Simulator]

# Define trace and NAM files for analysis and visualization

set tracefile [open “gpsr_trace.tr” w]

set namfile [open “gpsr_simulation.nam” w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Create a topography object (defines the area of the wireless network)

set topo [new Topography]

$topo load_flatgrid 1000 1000  ;# Create a 1000×1000 flat grid

# Set up the wireless network parameters

create-god 10  ;# Number of nodes

$ns node-config -adhocRouting GPSR \

-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 nodes and assign them positions

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

set node_($i) [$ns node]

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

}

# Define node positions manually (optional)

$node_(0) set X_ 100

$node_(0) set Y_ 100

$node_(1) set X_ 200

$node_(1) set Y_ 200

# Continue setting positions for all nodes…

# Define UDP agents for traffic

set udp0 [new Agent/UDP]

set udp1 [new Agent/UDP]

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

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

# Define CBR (Constant Bit Rate) traffic generator

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 0.5Mb

$cbr0 attach-agent $udp0

# Connect the UDP agents

$ns connect $udp0 $udp1

# Schedule the traffic flow

$ns at 1.0 “$cbr0 start”

$ns at 5.0 “$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

$ns at 6.0 “finish”

# Run the simulation

$ns run

  1. Run the Simulation

We can save the script as gpsr_simulation.tcl and execute it in NS2 with the below command:

ns gpsr_simulation.tcl

  1. Visualize the Simulation Using NAM

We can open the generated .nam file in the Network Animator (NAM) tool to envision the behaviour of GPSR in the network:

nam gpsr_simulation.nam

  1. Analyse the Trace File

The trace file (gpsr_trace.tr) will include detailed data regarding packet transmissions, routing decisions, and the performance of the GPSR protocol. We can investigate the file to verify:

  • Which routes were selected (greedy vs. perimeter mode).
  • The performance parameters such as packet delivery ratio and delay.
  • The path taken by the packets.
  1. Extend and Modify the Simulation
  • Node Mobility: Allow random mobility for nodes to monitor how GPSR manages dynamic topologies.
  • More Nodes and Traffic Sources: Insert more nodes and make several flows to monitor how GPSR manages more complex networks.
  • Link Failure Simulation: Launch link failures and monitor how GPSR switches among the greedy and perimeter modes.

Optional Enhancements:

  • Energy-Aware Routing: Change the GPSR protocol to deliberate node energy when creating routing decisions.
  • Void Handling: Test with scenarios in which greedy forwarding fails, and perimeter mode is needed to route around network voids.
  • QoS and Load Balancing: Prolong GPSR to manage QoS requirements or execute load balancing strategies.

Through this brief procedure, you can get to know more about the simulation process and their enhancements for Greedy Perimeter Stateless Routing projects including sample snippets using NS2 simulation tool. We are ready to give further insights and sample projects ideas regarding this subject in upcoming manual.

If you are seeking expert assistance in the development of a geographic routing protocol, and our team is ideally positioned to support you. Please reach out to us at phdprime.com, where we are eager to provide guidance throughout your project, ensuring optimal results in your Greedy Perimeter Stateless Routing Projects utilizing NS2 at every stage.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2