How to Start Unicast Routing Projects Using NS3

To start Unicast Routing projects using NS3, we follow these steps:

Steps to Start Unicast Routing Projects in NS3

  1. Understand Unicast Routing
  • Unicast Routing:
    • We observe the sending packet’s process from a single source to a single destination.
    • General protocols for unicast routing with static routing, dynamic routing like AODV, OLSR, and so on, and custom routing protocols.
  • Applications:
    • To construct the certain network scenarios including direct node-to-node interaction.
    • In unicast scenarios to measure the performance of routing protocol.
  1. Set Up NS3
  1. Install NS3 on the system:

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. Approach for Unicast Routing Projects
  • Option 1: We can utilize existing routing protocols such as Static Routing and AODV within NS3
  • Option 2: Make a custom unicast routing protocol by means of prolonging the Ipv4RoutingProtocol class.
  1. Basic Unicast Routing Using Static Routing

In NS3, static routing is the easiest way executing the unicast routing.

Code Example:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

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

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

using namespace ns3;

int main() {

NodeContainer nodes;

nodes.Create(4); // Create 4 nodes

PointToPointHelper pointToPoint;

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

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

// Install Internet stack

InternetStackHelper stack;

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

// Static routing: Define unicast routes

Ipv4StaticRoutingHelper staticRoutingHelper;

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

staticRoutingNode0->AddHostRouteTo(Ipv4Address(“10.1.3.2”), Ipv4Address(“10.1.1.2”), 1);

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

staticRoutingNode1->AddHostRouteTo(Ipv4Address(“10.1.3.2”), Ipv4Address(“10.1.2.2”), 2);

Simulator::Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Dynamic Unicast Routing Using AODV

For scenarios necessitating dynamic routing like mobile nodes so we can be utilized AODV.

Code Example:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/aodv-helper.h”

#include “ns3/mobility-module.h”

using namespace ns3;

int main() {

NodeContainer nodes;

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

// Set up mobility model

MobilityHelper mobility;

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

mobility.Install(nodes);

// Install AODV routing protocol

InternetStackHelper internet;

AodvHelper aodv;

internet.SetRoutingHelper(aodv);

internet.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper ipv4;

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

ipv4.Assign(nodes);

// Simulate traffic (e.g., from node 0 to node 4)

OnOffHelper onOff(“ns3::UdpSocketFactory”, Address(InetSocketAddress(Ipv4Address(“10.1.1.5”), 8080)));

onOff.SetConstantRate(DataRate(“1Mbps”));

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 Unicast Routing Implementation

If the existing protocols don’t match needs then we can be made a custom unicast routing protocol.

Steps:

  1. Define Custom Protocol: We need to prolong Ipv4RoutingProtocol and execute the necessary techniques like:
    • RouteOutput: It finds the route for outgoing packets.
    • RouteInput: It manages incoming packets.
    • NotifyInterfaceUp, NotifyInterfaceDown: Modernizes interface status.
  2. Skeleton Code:

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

namespace ns3 {

class CustomUnicastRouting : public Ipv4RoutingProtocol {

public:

static TypeId GetTypeId();

CustomUnicastRouting();

virtual ~CustomUnicastRouting();

// Override required methods

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:

std::map<uint32_t, Ipv4Address> routingTable; // Destination -> Next Hop

};

} // namespace ns3

  1. Performance Evaluation

Utilize following metrics to estimate the unicast routing protocol’s performance:

  • Packet delivery ratio (PDR).
  • Average delay.
  • Routing overhead.

Examine the outcomes to utilize logging and trace files:

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

Through this approach, we understood the concept of Unicast Routing and how to execute it then analyse the outcomes using NS3 environment. Furthermore, we will also be delivered advanced techniques or details relevant to this topic.

Our team is here to help you kick off your Unicast Routing Projects using NS3 with a comprehensive step-by-step guide, ensuring you can start and simulate your work efficiently. Reach out to us via email, and we will provide you with the latest project topics in this field. Let us handle your project performance for you!