How to Start an Optimal Routing Project Using NS2

To stimulate the Optimal Routing goals to detect optimize the available paths in a network according to the particular criteria like as minimum delay, maximum bandwidth, or minimum hops. This is frequently complete through routing protocols which dynamically measure the routes terms on the network environments.

In NS2, we can replicate the Optimal Routing using different routing techniques such as Shortest Path technique (Dijkstra’s), Link-State Protocols like OSPF, or Hybrid Algorithms which associates different parameter metrics. The idea is assure which the routing decisions are create the based on an optimal set for criteria like as minimal delay or packet loss.

Steps to Start an Optimal Routing Project Using NS2

  1. Install NS2

Assure that NS2 is installed on your system:

  • For Linux (Ubuntu/Debian-based):

sudo apt update

sudo apt install ns2

sudo apt install nam

  • For Windows: We can install the NS2 through a virtual machine or use Cygwin for replication.

Check the installation with:

ns

  1. Understand Optimal Routing Concepts

The optimal routing has includes the determining for the optimize paths in a network according to the certain parameter metrics:

  • Delay-based routing: Minimizing the latency for routing based delay.
  • Bandwidth-based routing: Maximizing the throughput in a bandwidth routing.
  • Hop-count-based routing: Minimizing the number of hops.

General technique for optimal routing:

  • Dijkstra’s Shortest Path Algorithm: Used in Link-State Routing we detect the minimum path according to the hop count or other parameter metrices.
  • OSPF (Open Shortest Path First): A routing protocol which uses Dijkstra’s techniques.
  • AODV (Ad hoc On-Demand Distance Vector): Frequently used in wireless networks for dynamic optimal routing.
  • OSPF with Multiple Metrics: OSPF can be extended to use several parameter metrics such as cost, delay, and bandwidth.
  1. Create the Network Topology

Designed for an optimal routing project, we will require describing the network topology in which the routing decisions can be estimated. The topology should permits the application of an optimal routing procedures.

Example topology:

  • Nodes: Routers or switches in the network.
  • Links: Network connection by particular the bandwidth, delay, and loss rate.
  1. Choose a Routing Protocol or Algorithm

We can apply or use a predefined routing protocol in NS2 for optimal routing. Some selections are:

  • Dijkstra’s Algorithm: Used to measure the minimum path according to the connection costs such as delay or bandwidth.
  • OSPF: Used the link-state information we calculate the optimal path in a network.
  1. Create the TCL Script for Optimal Routing

In this process, we will write a TCL script to replicate the optimal routing project in NS2. The script describes the network, routing protocol, and congestion flows.

Here’s a sample of a Dijkstra-based Optimal Routing project in NS2 using Link State Routing (OSPF):

Example TCL Script: Optimal Routing Using OSPF

# Create simulator object

set ns [new Simulator]

# Create nodes (routers)

set n0 [$ns node]  ;# Source

set n1 [$ns node]  ;# Intermediate node 1

set n2 [$ns node]  ;# Intermediate node 2

set n3 [$ns node]  ;# Destination

# Create links between nodes (Router links)

$ns duplex-link $n0 $n1 10Mb 10ms DropTail

$ns duplex-link $n1 $n2 10Mb 10ms DropTail

$ns duplex-link $n2 $n3 10Mb 10ms DropTail

# Define OSPF routing protocol to implement optimal routing (Dijkstra)

$ns node-config -routing-protocol OSPF

# Set traffic flow from n0 to n3 (source to destination)

set udp1 [new Agent/UDP]

set sink1 [new Agent/Null]

$sink1 attach-agent $n3

$udp1 attach-agent $n0

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 512

$cbr1 set interval_ 0.1  ;# Set rate for CBR traffic

$cbr1 attach-agent $n0

$ns connect $udp1 $sink1

# Set traffic start and stop times

$ns at 1.0 “$cbr1 start”

$ns at 5.0 “$cbr1 stop”

# Enable trace output to monitor routing and packet flow

$ns trace-all “optimal_routing_output.tr”

$ns namtrace-all “optimal_routing_output.nam”

# Run the simulation

$ns run

  1. Explanation of the TCL Script
  1. Network Topology:
    • 4 Nodes are created: The nodes are generating in n0 such as source, n1, n2, and n3 like a destination.
    • Links are described among the nodes through a bandwidth of 10Mb and delay of 10ms.
  2. Routing Protocol (OSPF):
    • The routing protocol is setting the OSPF that will use Dijkstra’s techniques to calculate the optimal paths according to the connection costs like as which can be set to various metrics like delay or bandwidth.
    • The node-Config-routing-protocol is OSPF command setting to the OSPF for optimal routing.
  3. Traffic Flow:
    • CBR (Constant Bit Rate) congestion is created from node n0 to n3 to replicate the continuous packet transmission.
    • The congestion starts at 1.0s and stops at 5.0s for replication time.
  4. Trace and NAM:
    • Trace-all: Replicate the outcomes in a specific for the suggestion files such as optimal_routing_output.tr that logs packet actions and routing decisions.
    • namtrace-all: Creates a .nam file like as optimal_routing_output.nam for envision the replication in NAM (Network Animator).
  1. Run and Analyze the Results

Next process for the replication, we can analyze the outcomes by NAM and trace files.

  1. NAM Visualization:
    • Used the envision for NAM to visualize the packet flow:

nam optimal_routing_output.nam

  1. Trace File Analysis:
    • The trace file like as optimal_routing_output.tr has contains the explained a data about packet flow, with routing decisions.
    • Used the file for awk or other tools to explain and analyze the trace file:

awk ‘{print $1, $2, $3, $4}’ optimal_routing_output.tr

This can be support for follow on how the routing decisions are made, the metrics used such as delay or bandwidth, and how the optimal path is selected according to the procedure.

  1. Extend the Optimal Routing Project

We can extend this Optimal Routing replication for in multiple paths:

  1. Multiple Traffic Flows:
    • Increase the several congestion flows from various source-destination pairs and we view on how OSPF calculates the optimal paths in a multi-flow network environment.
  2. Dynamic Changes in the Network:
    • Replicate the link failures or congestion and track on how the OSPF response through recalculating the optimal routes. This will need to ensure the Link-State Advertisements (LSA) for re-computation.
  3. Custom Metrics for Routing:
    • Spread the OSPF to use alters metrics for routing decisions. For sample, instead of hop-count, you can use delay, bandwidth, or packet loss as the metric for calculating the optimal route.
  4. Comparison with Other Routing Protocols:
    • Associate OSPF with other routing protocols such as AODV (Ad hoc On-Demand Distance Vector) or DVR (Distance Vector Routing) in terms of efficiency, delay, and throughput.
  5. Performance Metrics:
    • Estimate the throughput, delay, packet loss, and end-to-end delay below the various networks setting, like as varying connection delays, bandwidths, and traffic loads.

Here, we clearly demonstrate how to set up a basic creating the routing and implement an Optimal routing for enhance the network. For inquiries about the project, consult the additional manual we will provide.