How to Start XY Routing Projects Using NS3

To start XY Routing using NS3 that is a deterministic algorithm typically utilized within mesh or grid-based networks particularly in Network-on-Chip (NoC) and Wireless Mesh Networks. Depends on the X (horizontal) and Y (vertical) coordinates of nodes within a grid, it finds the routes.

Steps to Start XY Routing Project in NS3

  1. Understand XY Routing
  • What is XY Routing?
    • Initially, packets are routed over the X-axis (horizontal direction) while waiting for they attain the exact column, then over the Y-axis (vertical direction) to the destination.
    • In grid-based topologies, it prevents the deadlocks and livelocks.
  • Applications:
    • These routing used in Network-on-Chip (NoC) architectures.
    • Wireless sensor grids.
    • Large-scale wireless mesh networks.
  • Characteristics:
    • Deterministic and simple to execute it.
    • It functions within grid-based topologies including Cartesian coordinates.
  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:

./waf –run scratch/my-first

  1. Plan the XY Routing Simulation
  1. Define a Grid Topology:
    • Nodes are located in a grid including Cartesian coordinates.
  2. Implement XY Routing:
    • Packets are first routed parallel (X-axis), then perpendicularly (Y-axis).
  1. Option 1: Static XY Routing

In this technique, we can be executed a static XY routing algorithm by describing routes manually according to the node locations.

Example Code for Static Routing:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

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

#include “ns3/applications-module.h”

#include “ns3/mobility-module.h”

#include “ns3/ipv4-static-routing-helper.h”

using namespace ns3;

int main() {

// Create a 3×3 grid of nodes

NodeContainer nodes;

nodes.Create(9);

// Set up grid positions

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);

// Create links between nodes (horizontal and vertical)

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));

pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));

NetDeviceContainer devices;

for (int i = 0; i < 9; ++i) {

if (i % 3 != 2) {

// Horizontal links

devices.Add(pointToPoint.Install(nodes.Get(i), nodes.Get(i + 1)));

}

if (i < 6) {

// Vertical links

devices.Add(pointToPoint.Install(nodes.Get(i), nodes.Get(i + 3)));

}

}

// Install Internet stack

InternetStackHelper stack;

stack.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper ipv4;

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

ipv4.Assign(devices);

// Configure XY Routing

Ipv4StaticRoutingHelper staticRoutingHelper;

// Example: Define a route from Node 0 to Node 8 (using XY routing)

Ptr<Ipv4StaticRouting> staticRoutingNode0 = staticRoutingHelper.GetStaticRouting(nodes.Get(0)->GetObject<Ipv4>());

staticRoutingNode0->AddHostRouteTo(Ipv4Address(“10.1.0.9”), Ipv4Address(“10.1.0.2”), 1); // X-direction

staticRoutingNode0->AddHostRouteTo(Ipv4Address(“10.1.0.9”), Ipv4Address(“10.1.0.6”), 3); // Y-direction

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Option 2: Custom XY Routing Protocol

We can execute a custom XY routing protocol by prolonging Ipv4RoutingProtocol for extra flexibility.

Key Steps:

  1. We need to prolong the Ipv4RoutingProtocol class.
  2. Find routing decisions to utilize node positions that are recovered from the MobilityModel.
  3. Execute XY routing logic:
    • In the X-direction, initially send packets.
    • Then forward packets within the Y-direction.

Skeleton Code:

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

#include “ns3/mobility-module.h”

#include <cmath>

namespace ns3 {

class XyRoutingProtocol : public Ipv4RoutingProtocol {

public:

static TypeId GetTypeId();

XyRoutingProtocol();

virtual ~XyRoutingProtocol();

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:

Vector GetNodePosition(Ptr<Node> node);

Ptr<Ipv4Route> ComputeXyRoute(const Ipv4Header &header);

};

} // namespace ns3

Example of XY Routing Logic:

Ptr<Ipv4Route> XyRoutingProtocol::ComputeXyRoute(const Ipv4Header &header) {

Vector srcPosition = GetNodePosition(header.GetSource());

Vector dstPosition = GetNodePosition(header.GetDestination());

if (srcPosition.x != dstPosition.x) {

// Forward in X-direction

Ptr<Ipv4Route> route = Create<Ipv4Route>();

route->SetDestination(header.GetDestination());

route->SetGateway(…); // Choose a neighbor in the X-direction

return route;

} else if (srcPosition.y != dstPosition.y) {

// Forward in Y-direction

Ptr<Ipv4Route> route = Create<Ipv4Route>();

route->SetDestination(header.GetDestination());

route->SetGateway(…); // Choose a neighbor in the Y-direction

return route;

}

return nullptr; // Already at the destination

}

  1. Testing and Debugging
  1. Enable Logging:

NS_LOG=”XyRoutingProtocol” ./waf –run xy-routing

  1. Verify Routing Behavior:
    • We need to print routing tables for nodes confirming the exact XY paths.
    • Utilize .pcap files to seize packet flow:

pointToPoint.EnablePcapAll(“xy-routing”);

These projects cover the brief approach with relevant coding for XY Routing Projects that were initiated and executed using NS3 environment. Let me know if you want further details on this subject.

Our team specializes in Network-on-Chip (NoC) and Wireless Mesh Networks, ensuring you achieve the best outcomes for your project. To kick off your XY Routing Projects using NS3, we will provide you with a comprehensive step-by-step guide to help you start and simulate your work efficiently. Feel free to email us for the latest project topics in this field, and let us help you enhance your project performance.