How to Calculate Network End to End Delay in NS2

To calculate the End-to-End Delay in Network Simulator 2 (NS2), it is about the time taken for a packet to move from the source to the destination node. It is vital and used to compute the network’s performance, particularly in real-time application in which the low delay is important. In the below, we offered formula with process steps to compute this delay in NS2:

Formula for End-to-End Delay:

End-to-End Delay=Packet Reception Time−Packet Transmission Time\text{End-to-End Delay} = \text{Packet Reception Time} – \text{Packet Transmission Time}End-to-End Delay=Packet Reception Time−Packet Transmission Time

The average end-to-end delay can be measured by counting the delays of all packets received and dividing by the amount of packets obtained.

Steps to Calculate End-to-End Delay in NS2

  1. Set Up NS2 Simulation:

Begin by setting up a network simulation with traffic amongst source and a destination node. Below is a sample using UDP and CBR traffic.

Example TCL Script for Data Transmission:

# Create the simulator

set ns [new Simulator]

# Define the topology with two nodes: source and destination

set node_(0) [$ns node]

set node_(1) [$ns node]

# Create a duplex link between the nodes (1 Mbps bandwidth, 10ms delay)

$ns duplex-link $node_(0) $node_(1) 1Mb 10ms DropTail

# Attach UDP agents to nodes for sending and receiving data

set udp0 [new Agent/UDP]

set sink [new Agent/Null]

$ns attach-agent $node_(0) $udp0

$ns attach-agent $node_(1) $sink

$ns connect $udp0 $sink

# Set up Constant Bit Rate (CBR) traffic on the UDP agent

set cbr0 [new Application/Traffic/CBR]

$cbr0 attach-agent $udp0

$cbr0 set packetSize_ 512        ;# Packet size in bytes

$cbr0 set rate_ 1Mb              ;# Transmission rate (1 Mbps)

# Start and stop the traffic

$ns at 1.0 “$cbr0 start”

$ns at 10.0 “$cbr0 stop”

# Set up tracing to capture packet events

set tracefile [open out.tr w]

$ns trace-all $tracefile

# End the simulation after 12 seconds

$ns at 12.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

  1. Run the Simulation:

Execute the above TCL script using NS2 to create a trace file.

ns your_simulation_script.tcl

This will produce a trace file (out.tr) that contain logs of all the packet transmission and reception events.

  1. Analyze the Trace File:

You will calculate end-to-end delay by inspecting the time when packets are delivered and received. The trace file will has entries alike to the given below:

Sample Trace File Entries:

s 1.000000000 _0_ AGT  — 512 cbr 0 0.0 1.0 1.0

r 1.010000000 _1_ AGT  — 512 cbr 0 0.0 1.0 1.0

s 2.000000000 _0_ AGT  — 512 cbr 1 0.0 2.0 2.0

r 2.015000000 _1_ AGT  — 512 cbr 1 0.0 2.0 2.0

  • s: Packet sent event.
  • r: Packet received event.
  • 0: Source node.
  • 1: Destination node.
  • 512: Packet size in bytes.
  • 1.000000000: Time of transmission or reception.
  1. Calculate End-to-End Delay Using AWK Script:

Estimate the end-to-end delay by subtracting the send time from the receive time for each packet. The below AWK script calculates the average end-to-end delay from the trace file.

AWK Script to Calculate End-to-End Delay:

BEGIN {

total_delay = 0;

received_packets = 0;

}

# Record the time each packet was sent from the source (_0_)

$1 == “s” && $4 == “_0_” && $7 == “cbr” {

packet_time[$10] = $2;  # Store the transmission time indexed by packet ID

}

# Calculate the delay for each received packet at the destination (_1_)

$1 == “r” && $4 == “_1_” && $7 == “cbr” {

delay = $2 – packet_time[$10];  # Calculate the end-to-end delay

total_delay += delay;

received_packets++;

}

END {

if (received_packets > 0) {

avg_delay = total_delay / received_packets;

print “Average End-to-End Delay: ” avg_delay ” seconds”;

} else {

print “No packets were received!”;

}

}

  1. Run the AWK Script:

Store the AWK script as end_to_end_delay.awk and execute it on the trace file designed by NS2:

awk -f end_to_end_delay.awk out.tr

  1. Interpreting the Results:

The script will result the average end-to-end delay:

Example Output:

Average End-to-End Delay: 0.015 seconds

This result denotes that the average time taken for packets to move from the source to the destination is 0.015 seconds.

  1. Conclusion:

To measure End-to-End Delay in NS2:

  1. Set up a simulation with packet transmission amongst source and destination nodes.
  2. Execute the simulation to create a trace file.
  3. Assess the trace file using an AWK script to compute the time difference amongst packet transmission and reception for each packet.
  4. Compute the average delay by counting the delays and dividing by the total amount of packets received.

You can grasp the concept and can improve your knowledge from the delivered details on how to calculate the end-to-end delay in the ns2 simulation and also contains formulas and snippet codes. You can get any extra information of this estimation, if you need.

Determining the end-to-end delay in a network using NS2 can be quite challenging. We encourage you to stay connected with us, as we are here to provide you with the best guidance for optimal results. Please share all relevant parameter details, and we will ensure you receive the most effective comparative project outcomes. Should you have any project ideas or topics in mind, do not hesitate to reach out to us.