To simulate Layer 3 routed protocols in NS2, we are dealing with network layer protocols supports for routing packets via the networks. Instance of Layer 3 protocols include Internet Protocol (IP), Routing Information Protocol (RIP), Open Shortest Path First (OSPF), and others. NS2 maintain a variety of protocols, especially in the aspect of mobile ad-hoc networks (MANETs) or traditional wired and wireless networks.
Here’s a step-by-step guide to simulate Layer 3 routing protocols in NS2.
Steps to Simulate Layer 3 Routed Protocol Projects in NS2
- Install NS2
Make sure that NS2 is installed on the system. We can download it from the NS2 official website.
- Choose a Layer 3 Routing Protocol
Commonly used Layer 3 routing protocols that can be replicated in NS2 include:
- RIP (Routing Information Protocol)
- OSPF (Open Shortest Path First)
- AODV (Ad-hoc On-demand Distance Vector) for wireless ad-hoc networks
- DSR (Dynamic Source Routing)
- DVMRP (Distance Vector Multicast Routing Protocol) for multicast networks
- Set up Network Topology
In Layer 3 protocols, the routing tables are sustained at the network layer, and packets are transmitted hop-by-hop according to network addresses. We will describe nodes, links, and the routing protocol to be utilized.
Example TCL Script for Layer 3 Routing with RIP:
# Create a new simulator instance
set ns [new Simulator]
# Define trace and nam files for logging and visualization
set tracefile [open layer3_routing.tr w]
$ns trace-all $tracefile
set namfile [open layer3_routing.nam w]
$ns namtrace-all $namfile
# Create nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Create duplex links between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 20ms DropTail
$ns duplex-link $n2 $n3 1Mb 30ms DropTail
$ns duplex-link $n3 $n4 1Mb 10ms DropTail
# Enable routing protocol (in this case, RIP)
$ns rtproto RIP
# Define the network topology with positions (optional for static topology)
$n0 set X_ 50; $n0 set Y_ 100; $n0 set Z_ 0.0
$n1 set X_ 150; $n1 set Y_ 150; $n1 set Z_ 0.0
$n2 set X_ 250; $n2 set Y_ 200; $n2 set Z_ 0.0
$n3 set X_ 350; $n3 set Y_ 250; $n3 set Z_ 0.0
$n4 set X_ 450; $n4 set Y_ 300; $n4 set Z_ 0.0
- Set up Traffic between Nodes
We can replicate TCP or UDP traffic to measure the performance of the Layer 3 routing protocol. Here’s how to configure both types of traffic.
Example for TCP Traffic:
# Set up TCP connection between node 0 and node 4
set tcp0 [new Agent/TCP]
set sink0 [new Agent/TCPSink]
$ns attach-agent $n0 $tcp0
$ns attach-agent $n4 $sink0
$ns connect $tcp0 $sink0
# Create FTP traffic over TCP
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 2.0 “$ftp0 start”
$ns at 10.0 “$ftp0 stop”
Example for UDP Traffic (CBR):
# Set up UDP communication between node 1 and node 3
set udp0 [new Agent/UDP]
set null0 [new Agent/Null]
$ns attach-agent $n1 $udp0
$ns attach-agent $n3 $null0
# Generate CBR traffic over UDP
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set rate_ 100kb
$cbr0 attach-agent $udp0
$ns at 3.0 “$cbr0 start”
$ns at 12.0 “$cbr0 stop”
- Run the Simulation
Once the network and traffic are configured, save the TCL script (e.g., layer3_routing.tcl) and execute the simulation using NS2:
ns layer3_routing.tcl
This will create a trace file (.tr) and a NAM file (.nam) for evaluation and envision in Network Animator (NAM).
- Analyse the Simulation Results
To measure the performance of Layer 3 routing, we can utilize parameters like Packet Delivery Ratio (PDR), End-to-End Delay, and Routing Overhead. Utilize AWK or Python scripts to run the trace file and estimate these parameters.
Example AWK Script for Packet Delivery Ratio:
BEGIN { sent = 0; received = 0; }
{
if ($1 == “s” && $4 == “AGT”) { sent++; }
if ($1 == “r” && $4 == “AGT”) { received++; }
}
END { print “Packet Delivery Ratio = “, received/sent*100, “%”; }
We can also envision the packet routing and path selection in NAM to see how packets are transmitted via the network using the selected Layer 3 protocol.
- Simulating Other Layer 3 Routing Protocols
We can mimic other Layer 3 routing protocols by replacing RIP with:
- OSPF: Utilize an OSPF patch or execute it manually to replicate dynamic routing in large networks.
- AODV/DSR: For mobile ad-hoc networks, we can utilize AODV or DSR as Layer 3 routing protocols.
- Example Project Ideas for Layer 3 Routing Protocols
- Performance Comparison Between RIP and OSPF:
- Replicate RIP and OSPF in the same network and relate their performance based on packet delivery, end-to-end delay, and routing overhead.
- Layer 3 Routing in Mobile Networks:
- Replicate AODV or DSR in a mobile network and evaluate on how node mobility impacts routing performance.
- Energy-Efficient Layer 3 Routing:
- Adjust a Layer 3 routing protocol to contain energy parameters and measure its performance in sensor networks or MANETs.
- Multicast Routing with DVMRP:
- Replicate Distance Vector Multicast Routing Protocol (DVMRP) for multicast traffic and evaluate its performance based on packet loss and multicast efficiency.
In the above following steps briefly explain the simulation process for executing the Layer 3 routed protocols in ns2 simulation tool including example snippets and example project ideas for future improvement. We plan to elaborate further essential details about the Layer 3 routed protocols will be provided in further manual.
If you encounter difficulties in enhancing your project performance, our team is available to assist you. We provide comprehensive guidance tailored to your requirements for recreating Layer 3 Routed Protocol Projects. At phdprime.com, you can access a systematic approach to Internet Protocol (IP), Routing Information Protocol (RIP), and Open Shortest Path First (OSPF) within NS2. Additionally, we offer a selection of optimal research topics and a superior writing service.