How to Start Distance Routing Projects Using NS3

To start a Distance Routing project using NS3, we follow structured approach:

Steps to Start Distance Routing Projects in NS3

  1. Understand Distance Routing

In the network, distance routing contains the protocols in which each node sustains a table including the distance (or cost) to other nodes. Instances contain:

  • Distance Vector Routing: Nodes distribute its routing tables including neighbors determining the shortest paths.
  • Protocols:
    • RIP (Routing Information Protocol): It is classic distance vector protocol.
    • DSDV (Destination-Sequenced Distance-Vector Routing): A proactive protocol to utilize distance-vector principles.
  1. Install and 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: We execute an example replication, making sure that NS3 environment is properly installed:

./waf –run scratch/my-first

  1. Choose a Distance Routing Protocol
  • Use an Existing Protocol:
    • NS3 offers the DSDV since it is built-in example of distance routing.
    • RIP isn’t directly executed however it can be replicated by means of modifying the static routing protocol.
  • Implement a Custom Distance Vector Routing Protocol:
    • We can prolong the Ipv4RoutingProtocol for a new distance routing protocol.
  1. Using DSDV for Distance Routing

DSDV is executed already within NS3. Below is an instance replicates a network to utilize DSDV.

Example Code: DSDV Simulation

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/dsdv-helper.h”

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

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main() {

NodeContainer nodes;

nodes.Create(6); // Create 6 nodes

PointToPointHelper pointToPoint;

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

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

// Create links

NetDeviceContainer devices1 = pointToPoint.Install(nodes.Get(0), nodes.Get(1));

NetDeviceContainer devices2 = pointToPoint.Install(nodes.Get(1), nodes.Get(2));

NetDeviceContainer devices3 = pointToPoint.Install(nodes.Get(2), nodes.Get(3));

NetDeviceContainer devices4 = pointToPoint.Install(nodes.Get(3), nodes.Get(4));

NetDeviceContainer devices5 = pointToPoint.Install(nodes.Get(4), nodes.Get(5));

// Install Internet stack with DSDV

InternetStackHelper stack;

DsdvHelper dsdv;

stack.SetRoutingHelper(dsdv); // Set DSDV as the routing protocol

stack.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces1 = address.Assign(devices1);

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

Ipv4InterfaceContainer interfaces2 = address.Assign(devices2);

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

Ipv4InterfaceContainer interfaces3 = address.Assign(devices3);

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

Ipv4InterfaceContainer interfaces4 = address.Assign(devices4);

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

Ipv4InterfaceContainer interfaces5 = address.Assign(devices5);

// Create traffic from Node 0 to Node 5

OnOffHelper onOff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address(“10.1.5.2”), 9)));

onOff.SetConstantRate(DataRate(“500kbps”));

ApplicationContainer app = onOff.Install(nodes.Get(0));

app.Start(Seconds(1.0));

app.Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Custom Distance Routing Protocol

If we need to make distance routing protocol then we will require prolonging Ipv4RoutingProtocol.

Key Steps:

  1. Define a Custom Protocol Class:
    • We execute the distance-vector-based routing updates.
    • Distribute routing tables occasionally including neighbors.

Skeleton Code for Custom Protocol:

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

namespace ns3 {

class CustomDistanceRouting : public Ipv4RoutingProtocol {

public:

static TypeId GetTypeId();

CustomDistanceRouting();

virtual ~CustomDistanceRouting();

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;

void UpdateRoutingTable();

private:

std::map<uint32_t, uint32_t> routingTable; // Destination -> Cost

void ShareRoutingTable(); // Share routing updates with neighbors

};

} // namespace ns3

Implement Logic for Distance Updates:

In CustomDistanceRouting, we can execute:

  • Periodic Updates:
    • Periodically allocate routing tables with neighbors.
  • Bellman-Ford Algorithm:
    • According to the updates, we determine the shortest paths using this algorithm.
  1. Testing and Debugging
  1. Allow logging for debugging:

NS_LOG=”CustomDistanceRouting” ./waf –run your-simulation

  1. Envision the routing behavior:
    • Make sure that the routing table properly meets.
    • Verify for routing loops or inconsistencies.
  1. Performance Evaluation

Estimate the distance routing protocol’s performance to utilize parameters such as:

  • Convergence Time: Calculate the duration for routing tables to stable.
  • Packet Delivery Ratio (PDR): We measure the percentage of packets that are effectively distributed.
  • Control Overhead: We need to estimate the volume of routing control traffic.
  1. Advanced Enhancements
  • Mobility: Insert mobility models replicating the dynamic scenarios.
  • Fault Tolerance: Experiment routing behavior in node or link failures.
  • Scalability: We mimic large-scale networks to examine the performance.
  1. Visualization
  • Examine .pcap files that are made using Wireshark in the course of the simulation.
  • For visualization, we can utilize tools like Python or MATLAB to transfer routing metrics.

Here, we understand the process of Distance Routing Projects how it simulated and analysed the performance and visualized it using NS3 simulation tool and we also provided the sample complete script to execute distance routing. We will also be presented more insights on this topic.

If you are encountering difficulties in starting Distance Routing Projects with the NS3 tool, we recommend reaching out to the researchers at phdprojects.org. Our team is dedicated to ensuring your projects are completed with outstanding efficiency and quality. We will assist you in simulating your projects and offer you the most innovative ideas and topics for your work.