How to Develop Link State Routing Projects Using NS3

To develop the Link State Routing for used the NS3. Below are some project examples that concentrate on implementing LSR in NS3.

Steps to Develop Link State Routing Projects Using NS3

  1. Introduction to Link State Routing in NS3

Link State Routing (LSR) in which every router is kind of dynamic routing protocol:

  1. Handle the map for complete the network topology.
  2. Modify the link state data by other routers.
  3. It used the Dijkstra’s procedures to measure the shortest path.

In NS3, we can simulate Link State Routing Protocols (LSRP) using:

  • Open Shortest Path First (OSPF) (which is a real-world LSR protocol)
  • Custom Link-State Routing Protocols using NS3’s Ipv4RoutingHelper
  1. Setting Up NS3 for Link State Routing

Make sure NS3 is installed:

git clone cd ns-3-dev

./build.py –enable-examples

  1. Implementing Link State Routing in NS3

We will apply the basic Link State Routing replication using OSPF-like behavior.

3.1 Network Setup

  • 5 Nodes (Routers)
  • Point-to-Point Links
  • We execute for custom the Link-State Routing (LSR) Protocol
  • Observing the congestion flow

3.2 C++ Code for Link State Routing Simulation

link-state-routing.cc

#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-routing-helper.h”

#include “ns3/applications-module.h”

#include “ns3/flow-monitor-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“LinkStateRouting”);

int main(int argc, char *argv[]) {

// Enable Logging

LogComponentEnable(“LinkStateRouting”, LOG_LEVEL_INFO);

// Create Nodes (Routers)

NodeContainer nodes;

nodes.Create(5);

// Setup Point-to-Point Links

PointToPointHelper p2p;

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

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

NetDeviceContainer devices[5];

devices[0] = p2p.Install(nodes.Get(0), nodes.Get(1));

devices[1] = p2p.Install(nodes.Get(1), nodes.Get(2));

devices[2] = p2p.Install(nodes.Get(2), nodes.Get(3));

devices[3] = p2p.Install(nodes.Get(3), nodes.Get(4));

devices[4] = p2p.Install(nodes.Get(4), nodes.Get(0));

// Install Internet Stack with OSPF-like Link State Routing

InternetStackHelper internet;

Ipv4StaticRoutingHelper staticRouting;

Ipv4ListRoutingHelper listRouting;

listRouting.Add(staticRouting, 0);

internet.SetRoutingHelper(listRouting);

internet.Install(nodes);

// Assign IP Addresses

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces[5];

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

interfaces[i] = address.Assign(devices[i]);

address.NewNetwork();

}

// Setup Traffic Source (UDP Application)

uint16_t port = 9;

UdpEchoServerHelper echoServer(port);

ApplicationContainer serverApps = echoServer.Install(nodes.Get(4));

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(interfaces[4].GetAddress(1), port);

echoClient.SetAttribute(“MaxPackets”, UintegerValue(5));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

// Flow Monitor to Analyze Performance

FlowMonitorHelper flowMonitor;

Ptr<FlowMonitor> monitor = flowMonitor.InstallAll();

Simulator::Stop(Seconds(10.0));

Simulator::Run();

// Analyzing Performance Metrics

monitor->SerializeToXmlFile(“link-state-routing.xml”, true, true);

Simulator::Destroy();

return 0;

}

  1. Running the Simulation
  1. Move the file to NS3’s scratch directory:

mv link-state-routing.cc ns-3-dev/scratch/

  1. Compile and Run:

./waf –run scratch/link-state-routing

  1. Output Analysis:
    • The flow monitor output is stored the link-state-routing.xml.
    • Go to XML file in text editor for examine the packet loss, delay, and jitter.
  1. Performance Metrics for Link State Routing Testing

5.1 Measuring Throughput

Extract throughput using FlowMonitor:

Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier>(flowMonitor.GetClassifier());

std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats();

for (auto &flow : stats) {

std::cout << “Flow ID: ” << flow.first << ” Throughput: ”

<< (flow.second.rxBytes * 8.0 / 8.0 / 1024 / 1024) << ” Mbps” << std::endl;

}

5.2 Measuring Packet Loss

for (auto &flow : stats) {

double loss = ((flow.second.txPackets – flow.second.rxPackets) * 100.0) / flow.second.txPackets;

std::cout << “Packet Loss: ” << loss << “%” << std::endl;

}

5.3 Measuring Routing Efficiency

We take the packet can be measure the number of hops in routing efficiency:

for (auto &flow : stats) {

std::cout << “Hop Count: ” << flow.second.timesForwarded << std::endl;

}

  1. Advanced Enhancements
Feature Implementation in NS3
Dynamic Link Failures We launch the arbitrary connection failures using ErrorModel
Realistic Traffic Improve the further UDP/TCP applications for different congestion
Wireless Networks Exchange the Point-to-Point by Wi-Fi
Security Testing DDoS attacks replicate on routing tables
Interoperability Testing We link the OSPF by RIP or BGP
  1. Future Work
  • Incorporate the OSPF Protocol Fully (Custom OSPF implementation in NS3)
  • We associate for OSPF vs RIP vs AODV in Wireless Networks
  • For replicate a connection failures and recovery
  • Enhance the Routing by AI-based on Decision Making

 

For each of these projects, we can utilize the NS3 to replicate a network with different node configurations, traffic models, and mobility scenarios to evaluate the effectiveness of Dijkstra’s algorithm in changing conditions. Additional specific details regarding the dijikstra algorithms based examples will be provided if required.