How to Start Greedy Perimeter Stateless Routing Using NS2
To create a Greedy Perimeter Stateless Routing (GPSR) project using NS2 (Network Simulator 2) has includes the execution or replication GPSR, a protocol primarily model for a wireless networks and mobile ad-hoc networks (MANETs). Below is a detailed guide for starting your GPSR project in NS2.
Steps to Start Greedy Perimeter Stateless Routing Projects Using NS2
Step 1: Understand GPSR
- What is GPSR?
- GPSR is a geographic routing protocol.
- It used the greedy forwarding in which the packet is transmitting to the neighbour nearby to the destination.
- After greedy sending fails, perimeter routing is used to bypass obstacles.
- Key Components of GPSR:
- Greedy Forwarding: Transmit the packets for the neighbour nearby the destination.
- Perimeter Routing: Used the planar graph traversal after there’s no neighbour nearer to the destination than the prevent node.
- Stateless Design: Routers only handles the data about their direct neighbours.
Step 2: Set Up NS2 Environment
- Install NS2:
- Download NS2 from the NS2 Official Website.
- Validate the installation:
ns -version
- Learn Basic NS2 Scripting:
- Understand on how to create nodes, connection, and congestion flows in Tcl.
- Examine the sample in the ns-allinone-2.x/examples/ directory.
Step 3: Design Network Topology
- Define Nodes and Wireless Links:
set ns [new Simulator]
# Configure wireless topology
set opt(chan) Channel/WirelessChannel
set opt(prop) Propagation/TwoRayGround
set opt(netif) Phy/WirelessPhy
set opt(mac) Mac/802_11
set opt(ifq) Queue/DropTail/PriQueue
set opt(ll) LL
set opt(ant) Antenna/OmniAntenna
set opt(x) 1000
set opt(y) 1000
$ns node-config -adhocRouting GPSR \
-llType $opt(ll) \
-macType $opt(mac) \
-ifqType $opt(ifq) \
-ifqLen 50 \
-antType $opt(ant) \
-propType $opt(prop) \
-phyType $opt(netif) \
-channelType $opt(chan)
# Create nodes
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
- Set Node Positions:
- Allocate the geographic coordinates to nodes:
$n1 set X_ 100
$n1 set Y_ 200
$n1 set Z_ 0
$n2 set X_ 150
$n2 set Y_ 250
$n2 set Z_ 0
$n3 set X_ 300
$n3 set Y_ 350
$n3 set Z_ 0
- Define Traffic Sources and Sinks:
# Attach agents
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set sink [new Agent/Null]
$ns attach-agent $n3 $sink
$ns connect $udp $sink
# Add CBR application
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set interval_ 0.1
$ns at 1.0 “$cbr start”
Step 4: Implement GPSR Logic
GPSR is not natively executed in NS2, so we require to either replicate its behaviour or extend NS2 through a alter the GPSR execution.
Option 1: Tcl-Based GPSR Simulation
- Greedy Forwarding:
- Replicate the forwarding packets to the neighbour nearby to the destination.
proc greedyForward {currentNode neighbors dest} {
set minDist inf
set nextHop {}
foreach neighbor $neighbors {
set dist [distance $neighbor $dest]
if {$dist < $minDist} {
set minDist $dist
set nextHop $neighbor
}
}
return $nextHop
}
- Perimeter Routing:
- Maintain the cases in which greedy forwarding fails such as no neighbour closer to the destination.
proc perimeterRouting {currentNode neighbors dest} {
# Implement planar graph traversal (e.g., right-hand rule)
puts “Switching to perimeter mode at $currentNode”
}
Option 2: Custom GPSR Agent in C++
- Create a GPSR Routing Agent:
- Encompass the Agent class to execution GPSR functionality.
Example:
class GPSRAgent : public Agent {
public:
GPSRAgent();
void recv(Packet* p, Handler* h);
void forwardGreedy(Packet* p);
void forwardPerimeter(Packet* p);
private:
std::map<int, Position> neighborTable; // Neighbor ID -> Position
};
- Implement Core GPSR Functions:
- Neighbor Table Maintenance: Bring up-to-date positions of neighbours according to the beacon messages.
- Greedy Forwarding: Choose the neighbour nearby to the destination.
- Perimeter Routing: Used the planar graph traversal technique such as face routing.
- Compile and Link:
- Enhance the new agent to NS2’s Makefile and recompile:
make clean && make
Step 5: Simulate and Analyze
- Run the Simulation:
- Storage the script as gpsr_simulation.tcl and implement:
ns gpsr_simulation.tcl
- Visualize Results in NAM:
- Used the envision for NAM we follow on the packet forwarding and routing behaviours:
nam gpsr_simulation.nam
- Analyze the Trace File:
- Select the parameter such as:
- Packet delivery ratio.
- Average delay.
- Routing overhead.
- Select the parameter such as:
Step 6: Enhance the Project
- Dynamic Network Topologies:
- Replicate the node mobility using NS2’s arbitrary waypoint model:
$n1 setdest 500 500 10
- Optimize GPSR:
- Enhance for the mechanisms designed for energy-efficient routing or load balancing.
- Compare with Other Protocols:
- Replicate the AODV or DSR and associate their performance with GPSR.
- Scalability Testing:
- Validate the GPSR on larger networks through 50+ nodes.
Finished the entire process, you can acquire the simulation and execution process regarding the Greedy Perimeter Stateless Routing project offered in it using ns2 tool. An additional manual will provide answers to any further queries about this project.
Obtain optimal implementation guidance tailored to the specific requirements of your projects, as developed by our team. We specialize in wireless networks and mobile ad-hoc networks (MANETs), offering comprehensive explanations of these subjects. For professional assistance with your research endeavors, please reach out to phdprojects.org. We deliver exceptional research guidance, complemented by customized topic recommendations.