How to Start Layer 3 Routed Protocol Project Using NS2

To create a Layer 3 (Network Layer) routed protocols projects using NS2 (Network Simulator 2), follow the steps below. Layer 3 protocols concentrate on IP-based routing, responsible for determining the better path for packet forwarding using routing tables.

Steps to Start Layer 3 Routed Protocol Projects in NS2

  1. Set up the NS2 Environment

Assure the NS2 is installed and functional.

  1. Install NS2 (Ubuntu/Linux):

sudo apt-get update

sudo apt-get install ns2 nam xgraph

  1. Validate the installation:

ns

If successful, you will see the % prompt.

  1. Understand Layer 3 Routing Protocols

Layer 3 protocols have maintained the IP packet forwarding and route determination. Samples are including:

  • Static Routing
  • Dynamic Routing for sample AODV, DSDV, OSPF, RIP

Focus for Projects:

  • Static Routing: Manually are setting the static routes.
  • Dynamic Routing: Routes are defined and using the procedures and protocols.
  • Performance Metrics:
    • Packet Delivery Ratio (PDR)
    • End-to-End Delay
    • Throughput
    • Routing Overhead
  1. Design the Network Topology
  • Describe the Layer 3 network through nodes, connection, and traffic flows.
  • Traffic: Use the congestion for UDP/TCP with CBR/FTP applications.
  • Enhance the design for routing protocols such as DSDV, AODV, or OSPF.
  1. Create a TCL Script

Below is an NS2 Layer 3 Static Routed Protocol sample:

Layer 3 Routing TCL Script

# Initialize the Simulator

set ns [new Simulator]

set tracefile [open layer3_trace.tr w]

$ns trace-all $tracefile

set namfile [open layer3_nam.nam w]

$ns namtrace-all $namfile

# Define Colors for Visualization

$ns color 1 Blue

$ns color 2 Red

# Create Nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

# Define Links

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

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

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

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

# Define Static Routes (Layer 3 Routing Table)

$n0 add-route $n1 1

$n1 add-route $n2 1

$n2 add-route $n3 1

$n0 add-route $n3 1  ;# Direct route to n3

# Add Traffic Source (CBR over UDP)

set udp [new Agent/UDP]

set null [new Agent/Null]

$ns attach-agent $n0 $udp

$ns attach-agent $n3 $null

$ns connect $udp $null

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set rate_ 1Mb

# Schedule Traffic

$ns at 1.0 “$cbr start”

$ns at 5.0 “$cbr stop”

# Finish Procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam layer3_nam.nam &

exit 0

}

# Run Simulation

$ns at 6.0 “finish”

$ns run

  1. Run the Simulation
  1. Store the script as layer3_simulation.tcl.
  2. Process the script:

ns layer3_simulation.tcl

  1. Outputs:
    • Trace File: layer3_trace.tr
    • NAM Visualization: layer3_nam.nam
  1. Analyze Results

Performance Metrics:

  1. Packet Delivery Ratio (PDR):

awk ‘BEGIN {sent=0; received=0} {if ($1==”s”) sent++; if ($1==”r”) received++} END {print “PDR:”, received/sent*100 “%”}’ layer3_trace.tr

  1. End-to-End Delay: Measure the delay from the sent and received timestamps.
  2. Throughput: Use the tool AWK for calculate the total packets are received over time.

Visualization:

  • Use then envision tool for xgraph the plots:

xgraph pdr.xg throughput.xg delay.xg

  1. Extend the Project
  1. Dynamic Routing:
    • static routes are replace through protocols such as AODV or DSDV:

$ns rtproto AODV

  1. Node Mobility:
    • Use the mobility for Random Waypoint design for replicate the mobile nodes.
  2. Compare Routing Protocols:
    • It compares the routing protocols for replicate the performance of DSDV, AODV, and OSPF.
  3. Failure Recovery:
    • Connection or node failures are replicate calculate of duration of recovery.
  1. Document Results
  • Include:
    • It show the design for network topology
    • Then model gives the Simulation setup such as nodes, links, routing type
    • After outcomes gives the performance metrics for sample PDR, delay, throughput
    • Finally it contributes the comparative analysis for instance static vs dynamic routing

Key Notes

  • It concentrates on Layer 3 for IP routing.
  • It fixed the routing for some minimum networks.
  • Dynamic routing such as AODV and OSPF can maintain the mobility and scalability.

Overall, we had successfully implemented the layer 3 routed protocols in ns2 tool that effectively manage to enhance the coverage and capacity over the layer 3 routed protocols areas. We will another manual to address your queries about this project.