To simulate Equal-Cost Multi-Path (ECMP) routing using NS2, we will require replicating routing scenarios in which several paths among the origin and destination have identical costs, and traffic can be distributed over these paths to balance the load. ECMP is a routing approach that permits numerous paths with the similar cost to be utilized concurrently, which enhancing throughput and redundancy.
Here’s a step-by-step process on how to simulate ECMP routing using NS2.
Steps to Simulate ECMP Routing in NS2
- Set up NS2 Environment
Make sure that NS2 is installed and running on the system. We can check this by entering:
ns
If NS2 is properly installed then it will begin the NS2 shell.
- Understanding ECMP
Equal-Cost Multi-Path (ECMP) routing permits for traffic to be distributed over several paths, which have the similar cost. The target of ECMP is to balance traffic and avoid redundancy in case of link or path failure.
The network simulator NS2 does not have direct support for ECMP, however we can replicate this by setting up static routes with identical costs and distributing traffic over numerous paths using manual set up or changing existing routing protocols.
- Write a TCL Script for ECMP Routing
Following is an instance TCL script, which mimics ECMP routing by setting up several equal-cost paths among a source and a destination.
# Create a simulator object
set ns [new Simulator]
# Open trace and NAM output files
set tracefile [open out.tr w]
set namfile [open out.nam w]
$ns trace-all $tracefile
$ns namtrace-all $namfile
# Define network topology
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
# Create duplex links (with equal costs)
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n0 $n2 1Mb 10ms DropTail
$ns duplex-link $n1 $n3 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n3 $n4 512Kb 20ms DropTail
$ns duplex-link $n3 $n5 512Kb 20ms DropTail
# Enable static routing to mimic ECMP behavior
$ns rtproto Static
# Manually configure ECMP routes by setting multiple paths to the destination
# Configure n0 to route traffic to n4 through two equal-cost paths: via n1 and n2
$n0 add-route-to-destination $n4 1 ;# Path 1: n0 -> n1 -> n3 -> n4
$n0 add-route-to-destination $n4 2 ;# Path 2: n0 -> n2 -> n3 -> n4
# 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 cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
# Schedule the traffic to start and stop
$ns at 1.0 “$cbr0 start”
$ns at 4.5 “$cbr0 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
- Explanation of the Script
- Network Topology: The script describes six nodes, and there are two equal-cost paths from node n0 to node n4. Traffic can flow from n0 to n4 either through n1 -> n3 -> n4 or n2 -> n3 -> n4.
- Static Routing: The $ns rtproto Static command allows static routing. Two equal-cost routes are set up manually that utilising the add-route-to-destination command. The source node n0 is provided two paths to attain the destination n4.
- Traffic: A Constant Bit Rate (CBR) traffic source is connected to node n0, which transmitting traffic to n4.
- Running the Simulation
We can save the TCL script as ecmp_routing.tcl and execute it in the terminal:
ns ecmp_routing.tcl
It will make a trace file (out.tr) and a NAM file (out.nam) for network visualization.
- Visualizing the Simulation
To envision the simulation using NAM, run:
nam out.nam
In NAM, we will monitor how packets are transmitted from n0 to n4 using numerous equal-cost paths. The traffic can be routed through both paths that replicating ECMP behaviour.
- Load Balancing with ECMP
To execute load balancing among the numerous equal-cost paths, we can change the traffic distribution logic within NS2. It can be attained by dividing the traffic or routing diverse traffic flows via distinct paths.
For example, we can generate two distinct traffic flows from the similar source:
# Second traffic source (to balance load)
set udp1 [new Agent/UDP]
$ns attach-agent $n0 $udp1
$ns connect $udp1 $null0
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 512
$cbr1 set interval_ 0.01
$cbr1 attach-agent $udp1
# Schedule the second traffic source
$ns at 1.5 “$cbr1 start”
$ns at 4.5 “$cbr1 stop”
This configuration will make two separate traffic streams that can be routed over diverse paths.
- Analyzing the Trace File
The trace file (out.tr) encompasses detailed data regarding packet transmissions and routing decisions. We can be utilized grep or awk to extract important performance parameters like:
- Packet Delivery Ratio (PDR): Assess how many packets are effectively delivered to the destination.
- End-to-End Delay: Compute the time taken for packets to travel from source to destination.
- Load Balancing: Verify how traffic is distributed over numerous paths.
For example, to calculate the number of packets received:
grep “^r” out.tr | wc -l
- Performance Evaluation
We can assess the performance of ECMP routing by:
- Increasing traffic load: Maximizes the traffic to monitor how ECMP distributes load over the paths.
- Simulating link failures: We can utilize the rtmodel command to replicate link failures and observe how the network adjusts to path changes.
- Scaling the network: Insert more nodes and paths to experiment ECMP on a larger network topology.
In this manual, we explore the complete guide on get started the Equal-Cost Multi-Path (ECMP) routing projects within NS2 tool that replicated routing scenarios and estimated its performance. More information will be shared in another manual.
If you need help with your ECMP Routing Project, just send a message to phdprime.com! We’re excited to support you and make sure you get the best results at every stage of your project. If you’re looking for expert assistance with routing scenarios, we’re the right team for you!