To simulate Interior Gateway Protocols (IGP) in NS2 has includes to execute the protocols such as Open Shortest Path First (OSPF), Routing Information Protocol (RIP), or Intermediate System to Intermediate System (IS-IS), that are intended for routing in an autonomous system. While NS2 doesn’t deliver direct support for IGP protocols such as OSPF or IS-IS out-of-the-box, we want to manually design their behaviours, like link-state routing (for OSPF and IS-IS) or distance-vector routing (for RIP).
Here is an approach to achieve this process in ns2
Steps to Simulate IGP (OSPF) Protocol in NS2
- Install NS2:
- Make sure that we have NS2 installed and configured. NS2 can be installed on Linux-based systems or on Windows using Cygwin.
- Define Network Topology:
- Describe a simple or complex network topology with routers and links. Each router will sustain a link-state database and occasionally interchange link-state advertisements (LSAs) with its neighbours.
Example Topology:
set ns [new Simulator]
set r0 [$ns node] ;# Router 0
set r1 [$ns node] ;# Router 1
set r2 [$ns node] ;# Router 2
set r3 [$ns node] ;# Router 3
# Define links between routers
$ns duplex-link $r0 $r1 10Mb 10ms DropTail
$ns duplex-link $r1 $r2 10Mb 10ms DropTail
$ns duplex-link $r2 $r3 10Mb 10ms DropTail
- Simulate Link-State Routing (OSPF Behavior):
- OSPF performs by routers broadcasting their link-state information to all other routers in the network. Routers then build a network topology map and estimate the shortest path using Dijkstra’s algorithm.
Link-State Advertisement (LSA):
- Each router intermittently sends out LSAs to its neighbours that contain information about the router’s directly associated links and the status of those links.
Example: Simulating LSAs
proc send_lsa {router neighbors} {
puts “Router $router sending LSAs to neighbors: $neighbors”
foreach neighbor $neighbors {
update_link_state_database $router $neighbor
}
}
proc update_link_state_database {router neighbor} {
puts “Router $neighbor updating link-state database with info from $router”
# Add logic to update the routing table
}
# Simulate periodic LSA exchanges
$ns at 1.0 “send_lsa r0 {r1}”
$ns at 1.0 “send_lsa r1 {r0 r2}”
$ns at 1.0 “send_lsa r2 {r1 r3}”
- Implement Dijkstra’s Algorithm for Shortest Path Calculation:
- After receiving the LSAs from neighbours, routers utilize Dijkstra’s algorithm to estimate the shortest path to all other routers in the network.
Example: Shortest Path Calculation Using Dijkstra’s Algorithm
proc dijkstra {router} {
puts “Router $router is running Dijkstra’s algorithm to calculate the shortest path”
# Logic for Dijkstra’s algorithm to update routing table
}
# Trigger Dijkstra’s algorithm after receiving LSAs
$ns at 2.0 “dijkstra r0”
$ns at 2.0 “dijkstra r1”
$ns at 2.0 “dijkstra r2”
$ns at 2.0 “dijkstra r3”
- Simulate Traffic Flow Between Nodes:
- Once the routing tables are inhabited using the link-state information, we can replicate traffic flowing via the network. Generate traffic flows among the nodes to track on how packets are transmitted based on the shortest path.
Example: Simulating Traffic Flow
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
# Attach TCP agent to routers
$ns attach-agent $r0 $tcp
$ns attach-agent $r3 $sink
# Create a TCP connection between Router 0 and Router 3
$ns connect $tcp $sink
# Start traffic flow
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ns at 3.0 “$ftp start”
- Simulate Link-State Database Synchronization:
- In OSPF, routers must synchronize their link-state databases with their neighbours. If a new router links the network or if there are link changes, LSAs are re-advertised, and routers estimate the paths.
Example: Synchronization of Link-State Databases
proc synchronize_database {router neighbors} {
puts “Router $router synchronizing link-state database with neighbors: $neighbors”
foreach neighbor $neighbors {
# Logic to compare and synchronize databases
puts “Router $router sync with $neighbor”
}
}
# Synchronize the databases every 30 seconds (default OSPF behavior)
$ns at 30.0 “synchronize_database r0 {r1}”
$ns at 30.0 “synchronize_database r1 {r0 r2}”
$ns at 30.0 “synchronize_database r2 {r1 r3}”
- Simulate Link Failures and Recovery:
- One of the critical contexts of IGP protocols is how they manage network changes, like link failures. Replicate link failures and see how OSPF recalculates the routes according to the updated topology.
Example: Simulating a Link Failure
# Simulate a link failure between Router 1 and Router 2
$ns at 10.0 “$ns rtmodel-at 10.0 down $r1 $r2”
# Recalculate shortest path after the link failure
$ns at 11.0 “send_lsa r1 {r0}”
$ns at 11.0 “send_lsa r2 {r3}”
- Log and Analyse Network Behaviour:
- Utilize NS2’s tracing capabilities to log the interchange of LSAs, the updates of routing tables, and the traffic flow. This data can support you to evaluate how rapidly OSPF converges after a topology change and how the network performance is impacted.
Example: Enabling Trace Files
set tracefile [open ospf_simulation.tr w]
$ns trace-all $tracefile
After the simulation is done, evaluate the trace file to learn on how OSPF manage the link-state updates and traffic flow.
- Run the Simulation:
- After configuring the network topology, LSAs, traffic flows, and failure scenarios, execute the simulation.
$ns run
- Analyse Results:
- After processing the simulation, we can evaluate the trace file to measure key parameters such as:
- Convergence Time: How rapidly the network stabilizes after a topology change such as link failure.
- Routing Table Size: How large the routing tables are after the link-state updates.
- Packet Delivery Ratio: The percentage of packets successfully delivered to the destination.
- Routing Overhead: The number of routing information interchanged among routers.
- After processing the simulation, we can evaluate the trace file to measure key parameters such as:
Example: Evaluating Convergence Time in Trace Files
awk ‘/LSA update/ {print $0}’ ospf_simulation.tr
Advanced OSPF Simulation Ideas
- Area-Based OSPF Simulation:
- OSPF utilize a hierarchical model with areas to minimize the size of routing tables. We can replicate multiple OSPF areas by dividing the network into diverse sections and set up the routers to act as area border routers (ABRs).
Example: Defining OSPF Areas
proc define_ospf_area {router area} {
puts “Router $router belongs to OSPF area $area”
# Implement area-based routing and LSA exchange logic
}
$ns at 1.0 “define_ospf_area r0 0”
$ns at 1.0 “define_ospf_area r1 0”
$ns at 1.0 “define_ospf_area r2 1”
$ns at 1.0 “define_ospf_area r3 1”
- Simulating OSPF Network Types:
- OSPF supports diverse network types, like point-to-point, broadcast, and non-broadcast multi-access (NBMA). We can replicate these by exchanging the link properties among routers.
- Route Redistribution:
- We can replicate an OSPF communicating with other IGPs (such as RIP) by redistributing routes among the protocols. This can be helpful for validating on how OSPF manage routes learned from external networks.
Metrics for OSPF/IGP Simulation Analysis
- Convergence Time: The time it takes for the network to converge after a topology change like link failure.
- Routing Table Size: The size of the routing tables on each router after the LSAs have been interchanged.
- Packet Delivery Ratio: The percentage of packets successfully delivered to the destination.
- Link-State Update Overhead: The number of link-state routing information interchanged among routers.
In this manual, we demonstrate on how to simulate IGP protocols with NS2 by replicating their core functions, specifically it concentrate on OSPF-like behaviour (link-state routing), by the way OSPF is one of the most commonly utilized IGPs. If needed, we provide more information regarding this project in upcoming manual.
You can always rely on us for the best guidance on IGP Protocol Projects simulation. At phdprime.com, we offer personalized support to fit your unique requirements. Contact us, and we will provide you with engaging IGP Protocol Projects topics and ideas designed just for you. Our team specializes in IGP protocols like OSPF and IS-IS, so reach out for excellent results.