How to Develop Route Source Protocol Projects Using NS3

To develop the Route Source Protocol for used the NS3. We create the Route Source Protocol (Source Routing) projects in NS-3 has includes for execute a routing mechanism in which source node describe the whole path which packet will take complete the network. Different traditional for hop-by-hop routing, Source Routing permit the nodes to require the paths dynamically.

Steps to Develop Route Source Protocol Projects Using NS3

  1. Understanding Route Source Protocols

We assure that Route Source Protocol (RSP):

✅ The source node has define the complete route for previously distribute a packet.

✅ The route is embedded in the packet header.

✅ Intermediate nodes cannot perform the route discovery—they only forward packets terms on delivered route.

  1. NS-3 Setup for Route Source Protocol Development

(a) Install and download the latest version for NS3 in your system

sudo apt update

sudo apt install git g++ python3 python3-pip cmake

git clone

cd ns-3-dev

./ns3 configure –enable-examples –enable-tests

./ns3 build

  1. Implementing Route Source Protocol in NS3

There are two main methods for employ a Route Source Routing in NS3:

(A) Using an Existing Source Routing Protocol (DSR)

The Dynamic Source Routing (DSR) Protocol in NS3 is previously encouraged the source routing.

Example: Implementing DSR in NS-3

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/mobility-module.h”

#include “ns3/internet-module.h”

#include “ns3/dsr-module.h”

using namespace ns3;

int main() {

NodeContainer nodes;

nodes.Create(5);

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(10.0),

“DeltaY”, DoubleValue(10.0),

“GridWidth”, UintegerValue(5),

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

mobility.Install(nodes);

InternetStackHelper stack;

DsrMainHelper dsrMain;

DsrHelper dsr;

stack.Install(nodes);

dsrMain.Install(dsr, nodes);

Simulator::Run();

Simulator::Destroy();

return 0;

}

Implement the replication

./waf –run “scratch/dsr_example”

(B) Developing a Custom Route Source Protocol

We need to build a custom source routing protocol, follow these steps:

Step 1: Generate a New Routing Protocol Class

Describe the header file (my-source-routing.h)

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

#include “ns3/node-container.h”

class MySourceRouting : public ns3::Ipv4RoutingProtocol {

public:

static ns3::TypeId GetTypeId(void);

MySourceRouting();

virtual ~MySourceRouting();

virtual ns3::Ptr<ns3::Ipv4Route> RouteOutput(

ns3::Ptr<ns3::Packet> packet,

const ns3::Ipv4Header &header,

ns3::Ptr<ns3::NetDevice> oif,

ns3::Socket::SocketErrno &sockerr) override;

virtual bool RouteInput(

ns3::Ptr<const ns3::Packet> packet,

const ns3::Ipv4Header &header,

ns3::Ptr<const ns3::NetDevice> idev,

UnicastForwardCallback ucb,

MulticastForwardCallback mcb,

LocalDeliverCallback lcb,

ErrorCallback ecb) override;

};

Step 2: We measure the execution in Protocol Logic

Build the execution file for using this command my-source-routing.cc

#include “my-source-routing.h”

#include “ns3/log.h”

NS_LOG_COMPONENT_DEFINE(“MySourceRouting”);

NS_OBJECT_ENSURE_REGISTERED(MySourceRouting);

ns3::TypeId MySourceRouting::GetTypeId(void) {

static ns3::TypeId tid = ns3::TypeId(“ns3::MySourceRouting”)

.SetParent<ns3::Ipv4RoutingProtocol>()

.SetGroupName(“Internet”);

return tid;

}

MySourceRouting::MySourceRouting() {}

MySourceRouting::~MySourceRouting() {}

ns3::Ptr<ns3::Ipv4Route> MySourceRouting::RouteOutput(

ns3::Ptr<ns3::Packet> packet, const ns3::Ipv4Header &header,

ns3::Ptr<ns3::NetDevice> oif, ns3::Socket::SocketErrno &sockerr) {

NS_LOG_INFO(“Performing Source Routing for packet”);

return 0;

}

bool MySourceRouting::RouteInput(

ns3::Ptr<const ns3::Packet> packet, const ns3::Ipv4Header &header,

ns3::Ptr<const ns3::NetDevice> idev,

UnicastForwardCallback ucb, MulticastForwardCallback mcb,

LocalDeliverCallback lcb, ErrorCallback ecb) {

NS_LOG_INFO(“Forwarding packet according to predefined source route”);

return true;

}

Step 3: Incorporate a Source Routing for replication

Build a replication script (source-routing-simulation.cc)

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

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

#include “my-source-routing.h”

using namespace ns3;

int main() {

NodeContainer nodes;

nodes.Create(4);

 

PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, StringValue(“5Mbps”));

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

NetDeviceContainer devices;

devices = p2p.Install(nodes);

InternetStackHelper stack;

stack.Install(nodes);

Ptr<MySourceRouting> sourceRouting = CreateObject<MySourceRouting>();

nodes.Get(0)->AggregateObject(sourceRouting);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign(devices);

Simulator::Run();

Simulator::Destroy();

return 0;

}

Step 4: Compile and Run the Simulation

Compile the NS3

./waf

Implement the replication process for this approach

./waf –run “scratch/source-routing-simulation”

  1. Performance Analysis for Route Source Protocol
  • Utilized to examine the performance of route source protocol in FlowMonitor:

Ptr<FlowMonitor> flowMonitor;

FlowMonitorHelper flowHelper;

flowMonitor = flowHelper.InstallAll();

Simulator::Stop(Seconds(10.0));

Simulator::Run();

flowMonitor->SerializeToXmlFile(“results.xml”, true, true);

Run Analysis

python3 analyze_results.py

  1. Example Route Source Protocol Project Ideas

Now we are specific project ideas for Source Routing in NS-3:

1. Secure Source Routing

  • Employ the secure version of Source Routing which avoids the man-in-the-middle attacks.

2. Energy-Efficient Source Routing

  • We alter the Source Routing for choose the energy-efficient paths in wireless networks.

3. Source Routing in 5G Networks

  • Calculate the Source Routing to 5G millimeter-wave networks and examine the latency.

4. Source Routing for IoT Networks

  • Execute the Source Routing for network in Low-Power Wireless IoT networks.

5. Hybrid Source Routing (Multipath Routing)

  • We apply the estimation method for Multipath Source Routing (MSR) in load balancing.

 

In the end of the simulation, we all learn and get knowledge on about the Route Source protocol projects was implemented in ns3 simulation tool. Additional information will be shared regarding these projects in another manual.