How to Simulate GPSR Protocol Projects Using NS3

To simulate the GPSR (Greedy Perimeter Stateless Routing) protocol within NS3 that contains configuring a wireless ad-hoc network in which nodes are utilise the GPSR routing algorithm to forward packets according to the geographic location. The GPSR protocol makes use of node locations to create the greedy forwarding decisions. NS3 does not comprise a native execution of the GPSR protocol, however we can be replicated GPSR by executing the protocol logic, or we can be used an external modules, which offer GPSR support, like the NS3-GPSR module. Below is a simple instruction to simulate a GPSR-like protocol in NS3 by using external modules or by expanding NS3’s existing wireless simulation capabilities.

Steps to Simulate GPSR Protocol in NS3

  1. Install NS3 and NS3-GPSR Module

To replicate GPSR in NS3, we require to:

  1. Install NS3.
  2. Download and install the NS3-GPSR module from its external repository. We follow the guide for incorporating it with NS3.

Installing NS3-GPSR Module

  1. Clone the GPSR module repository:

git clone https://github.com/ashkanpajooh/ns3-gpsr.git

  1. Copy the GPSR files into your NS3 directory:

cp -r ns3-gpsr/* /path/to/your/ns3/src/

  1. Rebuild NS3:

cd /path/to/your/ns3/

./waf configure

./waf build

  1. Create a Simulation Script Using GPSR Protocol

After installing the NS3-GPSR module, we can make a replication utilising the GPSR protocol. This script illustrates how to replicate a wireless ad-hoc network using GPSR.

Example Simulation Using GPSR Protocol in NS3

a.Include Necessary Headers

Below headers are essential to configure the wireless communication, mobility, the GPSR routing protocol, and applications.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/gpsr-module.h”   // GPSR routing protocol header

#include “ns3/applications-module.h”

#include “ns3/netanim-module.h”

  1. Create and Install Nodes

Make a set of nodes are denoting the wireless ad-hoc network. These nodes will be used the GPSR routing protocol to communicate.

NodeContainer nodes;

nodes.Create(10);  // Create 10 nodes

  1. Configure Wireless Communication (Wi-Fi)

We can use the WifiHelper to configure wireless communication among the nodes. It is vital for simulating ad-hoc communication.

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);  // Set the Wi-Fi standard to 802.11g

wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);

WifiMacHelper wifiMac;

wifiMac.SetType(“ns3::AdhocWifiMac”);  // Ad-hoc MAC layer for nodes

NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

  1. Install GPSR Routing Protocol

Install the Internet stack (TCP/IP) on the nodes and set up them to use GPSR as the routing protocol.

InternetStackHelper internet;

GpsrHelper gpsr;  // GPSR routing protocol

// Use GPSR as the routing protocol

internet.SetRoutingHelper(gpsr);

internet.Install(nodes);

  1. Assign IP Addresses

Allocate an IP addresses to the nodes thus they can communicate across the wireless network.

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);  // Assign IP addresses

Ipv4InterfaceContainer interfaces = address.Assign(devices);

  1. Set up Mobility Model for Nodes

GPSR depend on the geographic positions of nodes to create the routing decisions. We can use the MobilityHelper to allocate positions and mobility to the nodes.

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,

“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”),

“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”));

mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,

“Speed”, StringValue(“ns3::UniformRandomVariable[Min=10.0|Max=20.0]”),

“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=1.0]”),

“PositionAllocator”, StringValue(“ns3::RandomRectanglePositionAllocator”));

mobility.Install(nodes);

  1. Set up Traffic Applications

We can replicate traffic among the nodes using applications like UDP Echo. One node will perform as a server, and another as a client.

  • Server (UDP Echo Server):

uint16_t port = 9;

UdpEchoServerHelper echoServer(port);

ApplicationContainer serverApp = echoServer.Install(nodes.Get(0));  // Server on node 0

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(20.0));

  • Client (UDP Echo Client):

UdpEchoClientHelper echoClient(interfaces.GetAddress(0), port);  // Client sends messages to node 0

echoClient.SetAttribute(“MaxPackets”, UintegerValue(50));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApp = echoClient.Install(nodes.Get(5));  // Client on node 5

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(20.0));

  1. Enable Tracing and Animation

Allow packet capture (PCAP) to investigate the communication among nodes and then we use NetAnim to envision the simulation.

wifiPhy.EnablePcapAll(“gpsr_simulation”);  // Enable PCAP tracing

AnimationInterface anim(“gpsr_simulation.xml”);  // Enable NetAnim animation

  1. Run the Simulation

Set the simulation stop time and we run the simulation.

Simulator::Stop(Seconds(20.0));  // Set the simulation stop time

Simulator::Run();  // Run the simulation

Simulator::Destroy();  // Clean up after the simulation

  1. Full Example Script for GPSR Simulation

Below is a comprehensive instance of a simulation script using GPSR in NS3.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/gpsr-module.h”

#include “ns3/applications-module.h”

#include “ns3/netanim-module.h”

using namespace ns3;

int main(int argc, char *argv[]) {

// Step 1: Create nodes (representing vehicles, sensors, or other wireless devices)

NodeContainer nodes;

nodes.Create(10);  // Create 10 nodes for the GPSR network

// Step 2: Configure Wi-Fi communication

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);  // Set Wi-Fi standard to 802.11g

wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);

WifiMacHelper wifiMac;

wifiMac.SetType(“ns3::AdhocWifiMac”);  // Ad-hoc mode for wireless devices

NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

// Step 3: Install GPSR routing protocol and Internet stack

InternetStackHelper internet;

GpsrHelper gpsr;  // GPSR routing protocol

internet.SetRoutingHelper(gpsr);

internet.Install(nodes);

// Step 4: Assign IP addresses

Ipv4AddressHelper address;

address.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(devices);

// Step 5: Set up mobility model

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,

“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”),

“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”));

mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,

“Speed”, StringValue(“ns3::UniformRandomVariable[Min=10.0|Max=20.0]”),

“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=1.0]”),

“PositionAllocator”, StringValue(“ns3::RandomRectanglePositionAllocator”));

mobility.Install(nodes);

// Step 6: Set up UDP Echo Server on node 0

uint16_t port = 9;

UdpEchoServerHelper echoServer(port);

ApplicationContainer serverApp = echoServer.Install(nodes.Get(0));  // Server on node 0

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(20.0));

// Step 7: Set up UDP Echo Client on node 5

UdpEchoClientHelper echoClient(interfaces.GetAddress(0), port);  // Client sends messages to node 0

echoClient.SetAttribute(“MaxPackets”, UintegerValue(50));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApp = echoClient.Install(nodes.Get(5));  // Client on node 5

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(20.0));

// Step 8: Enable tracing and animation

wifiPhy.EnablePcapAll(“gpsr_simulation”);

AnimationInterface anim(“gpsr_simulation.xml”);

// Step 9: Run the simulation

Simulator::Stop(Seconds(20.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Running the Simulation
  • Here, build and run the script using NS3’s waf build system:

./waf build

./waf –run gpsr_simulation

  1. Analyzing Results
  • PCAP Traces: The pcap files are generated in the course of the simulation can be examine using Wireshark to monitor packet exchanges and traffic.
  • NetAnim: We can envision the network topology and node movements within NetAnim with the help of .xml file generated during the simulation.
  1. Extending the Simulation

We can prolong this GPSR simulation by:

  • Altering the mobility model or importing the real-world mobility traces (e.g., from SUMO).
  • Replicating more complex traffic patterns or applications.
  • Adapting GPSR metrics to replicate various geographic routing behaviours.

The GPSR Protocol projects were effectively delivered and replicated through the above instruction using the NS3 platform. Additional informations also we will be presented if you required.

Send us all the information about your GPSR Protocol Projects to phdprime.com , and we’ll provide you with the best simulation outcomes. We provide you with a variety of research subjects and suggestions based on your demands.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2