How to Calculate Network Failover in NS2

To calculate the Network Failover in ns2 indicates the process of robotically shifting to a backup or redundant network path when a major link or node fails. We have to launch the link or node failures in ns2 to simulate the failover incidents and estimate how the network reacts. Important parameters for analysing the failover as well as the time it takes to switch to a backup route, packet loss during the transition and the entire network energy performance.

Here’s how you can calculate and analyze network failover in NS2:

Step-by-Step Implementation:

  1. Define Failover Metrics

When assessing failover in NS2, you might focus on the below metrics:

  • Failover time: The time it takes for the network to shift from a failed link or node to an substitute route.
  • Packet loss during failover: The amount of packets lost during the failover process.
  • Throughput before, during, and after failover: Computing the effect of failover on network performance.
  • Network recovery time: How rapidly the network restarts normal operations after failover.
  1. Set Up the Simulation in NS2

Start by designing a network topology that contains numerous routers amongst nodes, making sure that there are redundant paths for failover. We need to present a failover situation by closing a link or node during the simulation.

Below is an example of a basic network topology with two redundant paths:

# Create NS2 simulator instance

set ns [new Simulator]

# Open trace file for output

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

# Create links (two paths: n0-n1-n2 and n0-n3-n2)

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

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

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

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

# Set up traffic (UDP traffic from n0 to n2)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n2 $null0

$ns connect $udp0 $null0

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 500

$cbr0 set interval_ 0.005

$cbr0 attach-agent $udp0

# Schedule traffic start and stop

$ns at 0.5 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

# Introduce a link failure at time 2.0 seconds (simulate failover scenario)

$ns at 2.0 “$ns rtmodel-at 2.0 down $n0 $n1”

# End simulation after failover scenario

$ns at 5.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

  1. Simulate Failover Scenario

In the above sample, a link failure is launched at time 2.0 seconds using the rtmodel-at command. This disables the link amongst nodes n0 and n1, forcing the traffic to redirect through the backup path n0 -> n3 -> n2.

  • Failover event: This is the moment when the major path is interrupted, and the traffic should be redirected to the backup path.
  • Recovery event: This is when the network shifts to the backup route and normal operation restarts.
  1. Capture Data from the Trace File

NS2 creates a trace file (out.tr) that logs all network events like packet transmission, drops, and delays. You can use this file to assess the network activities during failover.

Key events to look for:

  • Packet transmission: Lines in the trace file where packets are delivered.
  • Packet drops: Lines that show packet drops because of the link failure.
  • Route change: When packets begin being dispatched over the backup path.

Example trace lines:

+ 0.500000 0 1 udp 500 ——- 1 0.0 0.0 1.0

– 0.510000 0 1 udp 500 ——- 1 0.0 0.0 1.0

d 2.010000 0 1 udp 500 ——- 1 0.0 0.0 1.0  # Packet drop due to link failure

+ 2.020000 0 3 udp 500 ——- 1 0.0 0.0 1.0  # Rerouting to backup path (n0 -> n3 -> n2)

  1. Analyze Failover Metrics

Failover Time

The failover time is the interval amongst the link failure and the time when traffic is efficiently rerouted across the backup path.

You can compute the failover time by discovering the time of the first packet drop (or failure event) and the time when packets are successfully transferred over the backup path.

Here’s an AWK script to estimate the failover time:

awk ‘

{

if ($1 == “d” && $3 == “0” && $4 == “1”) {  # Detect packet drop on failed link

failure_time = $2;

}

if ($1 == “+” && $3 == “0” && $4 == “3”) {  # Detect successful rerouting over backup path

recovery_time = $2;

if (failure_time != “”) {

failover_time = recovery_time – failure_time;

print “Failover Time:”, failover_time, “seconds”;

exit;  # Stop after calculating failover time

}

}

}’ out.tr

This script:

  1. Identifies the packet drop time because of the failed link.
  2. Detects the time when the first packet is successfully transmitted via the backup path.
  3. Computes the failover time as the difference between the two.

Packet Loss During Failover

The amount of packets lost during the failover can be defined by summing up the d (drop) events in the trace file.

Here’s an AWK script to measure the total number of dropped packets during failover:

awk ‘

{

if ($1 == “d” && $3 == “0” && $4 == “1”) {  # Count packet drops on the failed link

packet_drops++;

}

}

END { print “Total Packet Drops During Failover:”, packet_drops }’ out.tr

Throughput Before, During, and After Failover

Compute the throughput by counting the amount of packets successfully transferred before, during, and after the failover event.

You can use the below AWK script to calculate throughput in various time intervals:

awk ‘

{

if ($1 == “-” && $3 == “0” && $4 == “1” && $2 < 2.0) {  # Before failover

packets_before++;

}

if ($1 == “-” && $3 == “0” && $4 == “3” && $2 >= 2.0) {  # After failover (rerouted traffic)

packets_after++;

}

}

END {

print “Throughput Before Failover:”, packets_before / 2.0, “packets/sec”;

print “Throughput After Failover:”, packets_after / (5.0 – 2.0), “packets/sec”;

}’ out.tr

This script:

  • Measures the throughput before failover by summing up packets transmitted on the major link (n0 -> n1).
  • Calculates the throughput after failover by totaling packets transmitted on the backup link (n0 -> n3).
  1. Visualize Failover Data

You can use tools like python (matplotlib) to visualize the failover process or Excel to plot packet drops, throughput over time, or other key metrics.

Example Python Plot for Throughput Before and After Failover:

import matplotlib.pyplot as plt

# Example throughput data

time = [1.0, 2.0, 3.0, 4.0, 5.0]

throughput = [1000, 1000, 500, 1000, 1000]  # Example data showing a drop during failover

plt.plot(time, throughput, marker=’o’)

plt.title(‘Throughput Before and After Failover’)

plt.xlabel(‘Time (seconds)’)

plt.ylabel(‘Throughput (packets/sec)’)

plt.grid(True)

plt.show()

  1. Interpret the Results
  • Failover time: A low failover time represents a quick recovery, which is ideal for upholding network performance.
  • Packet loss: Less packet loss during failover is desirable. High packet loss may signify that the failover process is too slow or inefficient.
  • Throughput recovery: After failover, the network should ideally maintain or regain its actual throughput. Significant drops in throughput represent poor failover performance.

The given procedure will walk you the entire computational process on how to measure the failovers of network by simulating an environment using ns2 and compute the key metrics. You can understand how the packets are switched when the node or links fails during the transmissions.

Let us handle your customized Network Failover setup in the NS2 tool for optimal results. Just send us your parameter details, and we’ll assist you with the performance analysis.