How to Simulate Interior Protocol Projects Using NS2

To simulate Interior Gateway Protocols (IGPs) in NS2 has needs to setup the routing protocols that perform in an autonomous system (AS). The frequent IGPs that contain routing information protocol (RIP) and Open Shortest Path First (OSPF). NS2 supports RIP out of the box using the Distance Vector (DV) method, however for more advanced simulations such as OSPF, we required expand the NS2 or utilize external libraries.

In the below, we deliver the step-by-step procedures to achieve this approach in ns2.

Steps to Simulate Interior Protocol Projects in NS2

  1. Install NS2

Make sure that NS2 is installed on the system. We can install it on Linux-based systems using the following command:

sudo apt-get install ns2

For Windows, we need to utilize Cygwin or download a precompiled version of NS2.

  1. Simulating RIP (Routing Information Protocol)

Step-by-Step RIP Simulation

RIP is a simple Interior Gateway Protocol (IGP) that utilize distance vector routing to control the optimal path according to hop count. Here’s a basic TCL script to simulate RIP in NS2.

Example TCL Script for RIP Simulation

# Define simulator object

set ns [new Simulator]

# Open trace file to log simulation results

set tracefile [open rip_igp.tr w]

$ns trace-all $tracefile

# Open NAM file to visualize simulation

set namfile [open rip_igp.nam w]

$ns namtrace-all $namfile

# Define the number of nodes and simulation time

set val(nn) 4                ;# Number of nodes (routers)

set val(stop) 20.0           ;# Simulation stop time

set val(routing) DV          ;# Use Distance Vector (RIP-like protocol)

# Create the nodes (representing routers)

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

}

# Create duplex links between the nodes (wired network)

$ns duplex-link $node_(0) $node_(1) 10Mb 10ms DropTail

$ns duplex-link $node_(1) $node_(2) 10Mb 10ms DropTail

$ns duplex-link $node_(2) $node_(3) 10Mb 10ms DropTail

$ns duplex-link $node_(3) $node_(0) 10Mb 10ms DropTail

# Enable RIP protocol (Distance Vector)

$ns rtproto $val(routing)

# Setup traffic between nodes using UDP

set udp0 [new Agent/UDP]

$ns attach-agent $node_(0) $udp0

set null0 [new Agent/Null]

$ns attach-agent $node_(2) $null0

$ns connect $udp0 $null0

# Create a CBR (Constant Bit Rate) traffic source over UDP

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.01

$cbr0 attach-agent $udp0

# Start traffic at time 1.0 second

$ns at 1.0 “$cbr0 start”

$ns at 19.0 “$cbr0 stop”

# End the simulation after 20 seconds

$ns at $val(stop) “finish”

# Procedure to end the simulation

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam rip_igp.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Script

  • Nodes: Four nodes (representing routers) are generated and interrelated with duplex links.
  • RIP Protocol: The routing protocol is set to Distance Vector (DV), that replicate RIP-like behaviour.
  • Traffic: UDP traffic is generated among two routers, and the traffic pattern is defined using CBR (Constant Bit Rate).
  • Simulation End: The simulation executes for 20 seconds, after which it terminate.
  1. Running the Simulation

To execute the simulation, save the script as rip_igp.tcl, and then run it with NS2:

ns rip_igp.tcl

  1. Visualizing the Simulation

Once the simulation is done, we can envision the network traffic and topology using the NAM (Network Animator):

nam rip_igp.nam

This will open the NAM visualization tool, in which we can track the network behaviour, packet flow, and routing updates.

  1. Analysing the Trace File

The trace file (rip_igp.tr) encompasses detailed logs of packet transmissions, routing updates, and drops. We need to evaluate it using AWK, Python, or other tools to estimate parameters such as:

  • Packet Delivery Ratio
  • End-to-End Delay
  • Routing Overhead
  1. Simulating OSPF-Like Behavior in NS2

NS2 does not natively support OSPF (Open Shortest Path First) directly, however we can replicate OSPF-like behaviour by set up link-state routing protocols or by using custom extensions. OSPF is a more complex protocol related to RIP, as it utilizes Link State Routing (LSR) and needs topology information to be shared via all routers.

If we need to replicate OSPF, here are two options:

Option 1: Customizing Link-State Routing in NS2

NS2 supports Link-State Routing via extensions or by replicates the features using a custom protocol. To replicate OSPF-like behaviour, we will required to configured link-state routing in which each node distributes its entire link-state database with neighbouring nodes.

Here’s how we can describe Link-State Routing:

# Enable Link-State routing protocol (Custom implementation)

$ns rtproto LS

This permits Link State (LS) routing in NS2. We would require customizing the way packets are transmitted and execute OSPF’s certain characteristics like:

  • Area-based routing
  • Designated Routers (DR) and Backup DR
  • Flooding of link-state advertisements (LSAs)

Option 2: External Extensions or Libraries

Some external NS2 extensions and libraries deliver an OSPF support. We can download and install these extensions to replicate an OSPF more precisely. These cannot be officially maintained, however they can be helpful for OSPF-based projects.

  1. Simulating OSPF-like Network with Link State

Here is a basic instance which replicates a Link State routing mechanism that implements OSPF’s approach:

# Define the simulator object

set ns [new Simulator]

# Open trace file and NAM file

set tracefile [open ospf_linkstate.tr w]

$ns trace-all $tracefile

set namfile [open ospf_linkstate.nam w]

$ns namtrace-all $namfile

# Create nodes for routers

for {set i 0} {$i < 4} {incr i} {

set node_($i) [$ns node]

}

# Create duplex links

$ns duplex-link $node_(0) $node_(1) 10Mb 10ms DropTail

$ns duplex-link $node_(1) $node_(2) 10Mb 10ms DropTail

$ns duplex-link $node_(2) $node_(3) 10Mb 10ms DropTail

$ns duplex-link $node_(3) $node_(0) 10Mb 10ms DropTail

# Enable Link State Routing protocol

$ns rtproto LS

# Create UDP traffic

set udp0 [new Agent/UDP]

$ns attach-agent $node_(0) $udp0

set null0 [new Agent/Null]

$ns attach-agent $node_(2) $null0

$ns connect $udp0 $null0

# Configure CBR traffic

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.01

$cbr0 attach-agent $udp0

# Start traffic at 1 second

$ns at 1.0 “$cbr0 start”

$ns at 19.0 “$cbr0 stop”

# End simulation

$ns at 20.0 “finish”

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam ospf_linkstate.nam &

exit 0

}

# Run simulation

$ns run

  1. Modifying and Extending the Simulation

We can expand the simple simulation by:

  • Adding more nodes: mimic larger networks.
  • Changing traffic patterns: Utilize TCP or replicate real-world application protocols such as FTP or HTTP.
  • Comparing performance: Assess the parameters such as throughput, delay in diverse routing configurations (RIP vs. OSPF).

The given above simulation process was successfully and effectively simulated by using ns2 tool for Interior Gateway Protocols and also we provide the sample snippets for OSPF and LSR, detailed explanation scrip and the extension of simulation scenarios. Additional details will be updated later.

You can reliably count on us for superior guidance in Interior Protocol Projects simulation. At phdprime.com, we offer tailored support designed to address your unique requirements.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2