How to Start Greedy Perimeter Stateless Routing Using NS3

To start a Greedy Perimeter Stateless Routing (GPSR) project in NS3, we follow this detailed approach:

Steps to Start GPSR Projects in NS3

  1. Understand GPSR
  • GPSR Overview:
    • For wireless networks, GPSR is a geographic routing protocol.
    • It functions in two modes:
      1. Greedy Forwarding: Packets are sent to the neighbor nearby to the destination.
      2. Perimeter Routing: It is utilized once greedy sending is impossible like a void region exists.
  • Applications:
    • Vehicular Ad-hoc Networks (VANETs).
    • Wireless Sensor Networks (WSNs).
    • Geographic routing within mobile ad hoc networks.
  1. Set Up NS3
  1. Install NS3:

sudo apt update

sudo apt install g++ python3 git cmake

git clone https://gitlab.com/nsnam/ns-3-dev.git

cd ns-3-dev

./waf configure

./waf build

  1. Verify Installation: Run a sample simulation:

./waf –run scratch/my-first

  1. GPSR in NS3

NS3 environment doesn’t support GPSR’s built-in routing protocol. We can:

  1. Use an external implementation: Incorporate the third-party GPSR modules in NS3.
  2. Implement GPSR from scratch: We can prolong Ipv4RoutingProtocol and then execute greedy and perimeter forwarding logic.
  1. Option 1: Using a GPSR Module
  1. Download a GPSR Module:
    • Seek an external GPSR execution for NS3.
    • For instance, GPSR on GitHub.
  2. Integrate the GPSR Module:
    • Emulate the GPSR code in the src/ directory of the NS3 installation.
    • We need to modernize wscript into the src folder containing the GPSR module.
    • Construct NS3 to utilize following command:

./waf configure

./waf build

  1. Simulate a Network Using GPSR:
    • We can utilize the GPSR helper class that were offered by the module.
    • Example:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/gpsr-helper.h”

#include “ns3/point-to-point-module.h”

#include “ns3/mobility-module.h”

using namespace ns3;

int main() {

NodeContainer nodes;

nodes.Create(5); // Create 5 nodes

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(50.0),

“DeltaY”, DoubleValue(50.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);

mobility.Install(nodes);

InternetStackHelper internet;

GpsrHelper gpsr;

internet.SetRoutingHelper(gpsr);

internet.Install(nodes);

Ipv4AddressHelper ipv4;

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

ipv4.Assign(nodes);

Simulator::Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Option 2: Implement GPSR in NS3

If external GPSR module is not available or if we require modifying the GPSR, execute it.

Steps:

  1. Make a New GPSR Protocol Class:
    • We can prolong the Ipv4RoutingProtocol.
  2. Implement Core GPSR Logic:
    • Greedy Forwarding:
      • We need to send packets to the neighbor nearest to the destination.
    • Perimeter Routing:
      • Move around voids to utilize a right-hand rule.

Skeleton Code:

#include “ns3/ipv4-routing-protocol.h”

#include “ns3/mobility-module.h”

#include <map>

#include <vector>

namespace ns3 {

class GpsrRoutingProtocol : public Ipv4RoutingProtocol {

public:

static TypeId GetTypeId();

GpsrRoutingProtocol();

virtual ~GpsrRoutingProtocol();

Ptr<Ipv4Route> RouteOutput(Ptr<Packet> packet, const Ipv4Header &header,

Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) override;

bool RouteInput(Ptr<const Packet> packet, const Ipv4Header &header,

Ptr<const NetDevice> idev, UnicastForwardCallback ucb,

MulticastForwardCallback mcb, LocalDeliverCallback lcb,

ErrorCallback ecb) override;

private:

void GreedyForwarding(Ptr<Packet> packet, const Ipv4Header &header);

void PerimeterRouting(Ptr<Packet> packet, const Ipv4Header &header);

std::map<Ipv4Address, Vector> neighborTable; // Neighbor address -> position

};

} // namespace ns3

Greedy Forwarding Logic:

void GpsrRoutingProtocol::GreedyForwarding(Ptr<Packet> packet, const Ipv4Header &header) {

Vector destPosition = …; // Extract destination position

Vector closestNeighbor;

double minDistance = std::numeric_limits<double>::max();

for (auto &neighbor : neighborTable) {

double distance = CalculateDistance(neighbor.second, destPosition);

if (distance < minDistance) {

minDistance = distance;

closestNeighbor = neighbor.second;

}

}

if (minDistance < std::numeric_limits<double>::max()) {

// Forward packet to closest neighbor

} else {

// Switch to perimeter routing

PerimeterRouting(packet, header);

}

}

Perimeter Routing Logic:

void GpsrRoutingProtocol::PerimeterRouting(Ptr<Packet> packet, const Ipv4Header &header) {

// Implement right-hand rule for perimeter forwarding

}

As illustrated above, we executed the implementation process and example outline for Greedy Perimeter Stateless Routing that was initiated in NS3 environment. So if you want to learn more about Greedy Perimeter Stateless Routing Projects using NS3, feel free to contact us! We’ll give you the basic steps and a detailed guide to help you out.