How to Simulate Unicast Routing Projects Using NS2

To simulate Unicast Routing projects using NS2, we will concentrate on scenarios in which packets are transmits from a single source node to a single destination node, by way of different to multicast or broadcast routing. NS2 supports unicast routing via numerous routing protocols, that involves dynamic protocols such as AODV, DSR, and OLSR, or we can set up static unicast routing by manually setting routes.

Here’s a step-by-step guide to simulate unicast routing using NS2.

Steps to Simulate Unicast Routing in NS2

  1. Set up NS2 Environment

Make sure NS2 is properly installed and running. We need to validate this by typing:

ns

If NS2 is properly installed, the command will open the NS2 shell.

  1. Understanding Unicast Routing

In Unicast Routing, data packets are transmit from one source to one destination. Depending on the network environment, we can mimic static or dynamic unicast routing:

  • Static Routing: Routes are physically configured and do not change in the course of the simulation.
  • Dynamic Routing: Routing protocols like AODV (Ad hoc On-Demand Distance Vector) or DSR (Dynamic Source Routing) identify routes enthusiastically according to network conditions.
  1. Write a TCL Script for Unicast Routing

Below is a basic sample of unicast routing using a dynamic routing protocol (AODV) to replicate a unicast transmission.

# Create a simulator object

set ns [new Simulator]

# Open trace and NAM files

set tracefile [open out.tr w]

set namfile [open out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Define the network topology

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

# Create duplex links between nodes

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

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

$ns duplex-link $n2 $n3 512Kb 20ms DropTail

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

# Set dynamic routing protocol to AODV (can also use DSR, OLSR, etc.)

$ns rtproto AODV

# Create a UDP agent and attach it to node n0 (source)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

# Create a Null agent and attach it to node n4 (destination)

set null0 [new Agent/Null]

$ns attach-agent $n4 $null0

# Connect the source (n0) to the destination (n4)

$ns connect $udp0 $null0

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

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set interval_ 0.005

$cbr attach-agent $udp0

# Schedule the traffic to start and stop

$ns at 1.0 “$cbr start”

$ns at 4.5 “$cbr 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
  • Unicast Routing: The routing protocol $ns rtproto AODV is utilized to enable unicast routing in a dynamic environment. AODV determines the route from source (n0) to destination (n4) on demand.
  • Network Topology: This replication describes five nodes associated in a chain, with each link having different latency and bandwidth.
  • Traffic: A Constant Bit Rate (CBR) traffic source is configured to create traffic from n0 to n4.
  1. Running the Simulation

Save the script as unicast_routing.tcl and execute it in the terminal:

ns unicast_routing.tcl

This will create a trace file (out.tr) and a NAM file (out.nam) for envisioning the network.

  1. Visualizing the Simulation

To envision the simulation using NAM, run:

nam out.nam

We will be able to see how packets are transmitting from the source (n0) to the destination (n4) using dynamic unicast routing.

  1. Modifying the Simulation

We can adjust the simulation to validate different environment:

  • Change the routing protocol: We can switch from AODV to another unicast routing protocol such as DSR or OLSR.
  • Simulate link failures: We can replicate a link failure by using the rtmodel command.

For example, to replicate a link failure among n1 and n2 at 2.5 seconds:

# Simulate a link failure at 2.5 seconds

$ns rtmodel-at 2.5 down $n1 $n2

# Restore the link at 4.0 seconds

$ns rtmodel-at 4.0 up $n1 $n2

This will force the routing protocol to identify an alternative path, demonstrate on how dynamic unicast routing adapt to changes in the network topology.

  1. Static Unicast Routing (Manual Configuration)

If we want to replicate static unicast routing, in which routes are manually set, utilize the following approach:

# manually configure the route (static routing)

$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

This simulates an environment in which routing paths are predefined and do not change in the course of the simulation.

  1. Analysing the Trace File

The trace file (out.tr) delivers detailed information about packet transmissions, routing updates, and other events. We can utilize awk or grep to extract parameters like:

  • Packet Delivery Ratio (PDR): Evaluate on how many packets reach the destination.
  • End-to-End Delay: Estimate the time it takes for packets to travel from source to destination.
  • Routing Overhead: Total the number of control packets created by the routing protocol.

For example, to count the amount of packets received at the destination:

grep “^r” out.tr | wc -l

  1. Performance Evaluation

We can measure the performance of unicast routing in different conditions by:

  • Increasing network size: incorporate more nodes and links to replicate a larger network.
  • Simulating mobility: Establish mobile nodes to learn on how unicast routing adjusts in mobile ad-hoc networks (MANETs).
  • Varying traffic patterns: Test with different types of traffic, like TCP rather than UDP, or alteration the traffic intensity.

We had explicit the information about the simulation process with examples regarding the Unicast Routing projects that was simulated using the tool of ns2. We plan to elaborate on the Unicast Routing project procedure in other simulation scenarios.If you’re having difficulty achieving perfect simulations for your Unicast Routing Projects using NS2, look no further than phdprime.com. We guarantee outstanding results. Share your project details with us, and we will provide you with the guidance you need.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2