How to Simulate Static Routing Projects Using NS2

To simulate Static Routing in NS2 has needs to set up the predefined routes for all nodes in the network that do not change in the course of the simulation, nevertheless of network conditions. This is beneficial for the environment in which the network topology is stable, and routes are physically set to follow a certain path.

Below is a guide to simulate static routing projects using NS2.

Steps to Simulate Static Routing in NS2

  1. Set up NS2 Environment

Make sure that NS2 is correctly installed and configured. We need to validate the installation by executing:

ns

If it’s installed properly, this command will initiate the NS2 prompt.

  1. Understanding Static Routing

In Static Routing, routes among source and destination nodes are manually configured and remain fixed throughout the simulation. Different dynamic routing, static routes do not adjust to changes in the network, like link failures or congestion.

  1. Writing a TCL Script for Static Routing

Here is a simple instance to configure a static routing simulation in NS2.

# Create a new simulator object

set ns [new Simulator]

# Open trace and NAM output files

set tracefile [open out.tr w]

set namfile [open out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Create network nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

# Define the links between nodes

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

$ns duplex-link $n1 $n2 1Mb 15ms DropTail

$ns duplex-link $n2 $n3 1Mb 20ms DropTail

$ns duplex-link $n3 $n4 1Mb 25ms DropTail

# Enable static routing

$ns rtproto Static

# Manually set the static routes

$n0 add-route-to-destination $n4 1

$n1 add-route-to-destination $n4 1

$n2 add-route-to-destination $n4 1

$n3 add-route-to-destination $n4 1

# Attach traffic source (UDP) to node n0 and destination (Null) to node n4

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n4 $null0

$ns connect $udp0 $null0

# Create a CBR traffic generator and attach it to the UDP agent

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.01

$cbr0 attach-agent $udp0

# Schedule the traffic generation

$ns at 0.5 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

$ns at 5.0 “finish”

# Define the finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam out.nam &

exit 0

}

# Run the simulation

$ns run

  1. Explanation of the Script
  • Routing Protocol: $ns rtproto Static permits static routing,in which the routes are manually configured.
  • Network Topology: This simulation encompasses of five nodes associated in a chain topology.
  • Manual Route Configuration: Static routes are physically set using the add-route-to-destination command. Each node is initiated to route packets via its direct neighbours toward the destination node.
    • For example, n0 is configured to send packets to n4 via n1.
  • Traffic: A Constant Bit Rate (CBR) traffic source is created from node n0 and directed to node n4.
  1. Running the Simulation

To process the simulation, save the TCL script (e.g., as static_routing.tcl) and executed it using the following command:

ns static_routing.tcl

This will create a trace file (out.tr) and a NAM visualization file (out.nam).

  1. Viewing the Results

We can open the NAM file to envision the network and routing behaviour:

nam out.nam

In the visualization, we will see how the static routes guide the packets along predefined paths.

  1. Customizing the Simulation

We need to adjust the simulation to validate different environment settings:

  • More Complex Topologies: Incorporate more nodes and links to generate more complex networks, and physically set the static routes for each node.
  • Vary Traffic Types: Test with different kinds of traffic (such as TCP rather than UDP) and diverse traffic patterns.
  • Link Failures: Validate the effect of link failures on static routing by manually disabling links in the course of the simulation (note that static routes do not adjust to such changes).
  1. Simulating Link Failures

If you need to replicate a link failure and track the static routing’s behaviour (i.e., packets not getting delivered because of the fixed routes), we need to incorporate the following lines to the script:

# Simulate link failure between n2 and n3 at 2.5 seconds

$ns rtmodel-at 2.5 down $n2 $n3

# Restore the link at 4.0 seconds

$ns rtmodel-at 4.0 up $n2 $n3

In this case, the routing will not modify, and packets can be dropped in the course of the link failure.

  1. Analyse the Trace File

The trace file (out.tr) will encompasses detailed information about packet transmissions, routing decisions, and link changes. We need to evaluate this file to assess metrics such as packet delivery ratio, delay, and throughput. For example:

grep “^r” out.tr | wc -l  # Count the number of received packets

  1. Performance Evaluation

We need to measure the performance of static routing by evaluating key parameter:

  • Packet Delivery Ratio: The percentage of packets successfully delivered to the destination.
  • Latency: The average time it takes for packets to travel from source to destination.
  • Routing Overhead: There is no routing overhead in static routing as no control messages are interchanged.

In this page, we clearly showed the simulation process on how the Static Routing perform in the ns2 tool and also we offered the complete elaborated explanation to understand the concept of the simulation. We plan to deliver the more information regarding the Static Routing in further manual.

If you’re looking to simulate Static Routing Projects using the NS2 tool, our team of experts at phdprime.com is here to help. Just share your project details with us, and we’ll support you through every step of the process. Plus, we can provide you with some great project ideas and insights on network topology from our knowledgeable team.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2