How to Implement Network Delay Assessment in NS2
To implement the Network delay assessment within NS2 that has includes to simulating a network and evaluating the important delay metrics, like end-to-end delay, propagation delay, and queuing delay. We can estimate those delays by examine the packet flows among the nodes and calculating the time it takes for packets to travel from source to end. In NS2, delivers mechanisms to trace packet events that can use to estimate the latency. We present step-by-step basic approaches to execute it in NS2:
Key Types of Network Delays:
- Propagation Delay: The time it gets for a signal to propagate from the sender to receiver.
- Queuing Delay: The time a packet uses in the queue before when processed.
- Transmission Delay: The time taken to push all packet bits into the link.
- End-to-End Delay: From the source to the destination, the total delay expert by a packet that contains the propagation, queuing, and transmission delays.
Steps to Implement Network Delay Assessment in NS2
- Install NS2
Make sure that NS2 is installed on the system. Then we can download NS2 from the NS2 website.
- Create a Basic Network Topology
Initially, we can make a basic network topology with nodes and links to estimate the delay among the nodes. We will use a simple topology with two nodes (n0 and n1) connected by a duplex link.
Example: Simple Network Topology for Delay Measurement
# Define a simulator object
set ns [new Simulator]
# Define trace and nam files for output
set tracefile [open out.tr w]
set namfile [open out.nam w]
$ns trace-all $tracefile
$ns namtrace-all $namfile
# Define a ‘finish’ procedure to end the simulation and visualize in NAM
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
# Create two nodes
set n0 [$ns node]
set n1 [$ns node]
# Create a duplex link between the nodes
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
# Create a TCP agent and attach it to node n0
set tcp [new Agent/TCP]
set sink [new Agent/TCPSink]
$ns attach-agent $n0 $tcp
$ns attach-agent $n1 $sink
# Connect the TCP agent to the TCPSink
$ns connect $tcp $sink
# Create FTP traffic over TCP
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp start 1.0
$ftp stop 5.0
# Schedule the simulation end
$ns at 6.0 “finish”
# Run the simulation
$ns run
- Explanation of the Script
- Nodes and Links: The network contains the two nodes (n0 and n1) are connected through the duplex link including a bandwidth of 1 Mbps and a delay of 10 ms.
- Traffic (FTP over TCP): FTP traffic is produced across the TCP to replicate the packet flow among the two nodes.
- End of Simulation: After 6 seconds, the simulation ends and the outcomes are written to trace files for analysis.
- Run the Simulation
We can save the script as delay_assessment.tcl then run it in NS2 using the given command:
ns delay_assessment.tcl
It will produce a trace file (out.tr) and a NAM file (out.nam) for visualization.
- Measure Delay from the Trace File
When the simulation is finished, we can evaluate the trace file to various kinds of delays.
- Calculating End-to-End Delay
End-to-end delay can be estimated by calculating the time variation among while a packet is forward from the source and when it is received at the end.
Given below is an example of how to utilise AWK to assess the end-to-end delay from the trace file. Consider, we are estimating the delay for packets sent from n0 to n1 through TCP.
AWK Script to Calculate End-to-End Delay:
We can save this script as end_to_end_delay.awk:
# This script calculates the end-to-end delay for packets in NS2 trace files
# Fields:
# 1: Event, 2: Time, 3: From Node, 4: To Node, 6: Packet ID, 8: Packet Size, 9: Source, 10: Destination, 11: Protocol
# Store send time of packets sent from node n0
$1 == “s” && $3 == “0” && $11 == “tcp” {
send_time[$6] = $2
}
# When packet is received at node n1, calculate the delay
$1 == “r” && $4 == “1” && $11 == “tcp” {
if ($6 in send_time) {
delay = $2 – send_time[$6]
total_delay += delay
count++
print “Packet ID: ” $6 ” End-to-End Delay: ” delay ” seconds”
}
}
# At the end, print the average delay
END {
if (count > 0) {
print “Average End-to-End Delay: ” total_delay / count ” seconds”
} else {
print “No packets received.”
}
}
We can run the AWK script on the trace file to calculate the end-to-end delay:
awk -f end_to_end_delay.awk out.tr
- Queueing and Transmission Delay
To estimate the queuing delay, we can evaluate the time a packet spends in the queue before when processed. It can be completed by observing at the packet events in the trace file (q for enqueue, d for drop, etc.).
Given below is an instance of how to compute queuing delay using an AWK script:
AWK Script to Calculate Queuing Delay:
# Store enqueue time for packets at node n0
$1 == “+” && $3 == “0” && $11 == “tcp” {
enqueue_time[$6] = $2
}
# When packet is dequeued at node n0, calculate the queuing delay
$1 == “-” && $3 == “0” && $11 == “tcp” {
if ($6 in enqueue_time) {
queuing_delay = $2 – enqueue_time[$6]
total_queuing_delay += queuing_delay
count++
print “Packet ID: ” $6 ” Queuing Delay: ” queuing_delay ” seconds”
}
}
# At the end, print the average queuing delay
END {
if (count > 0) {
print “Average Queuing Delay: ” total_queuing_delay / count ” seconds”
} else {
print “No packets dequeued.”
}
}
We can run this script likewise to compute the queuing delay:
awk -f queuing_delay.awk out.tr
- Transmission and Propagation Delay
- Transmission Delay: We can estimate the transmission delay as:
Transmission Delay=Packet Size (in bits)Link Bandwidth (in bps)\text{Transmission Delay} = \frac{\text{Packet Size (in bits)}}{\text{Link Bandwidth (in bps)}}Transmission Delay=Link Bandwidth (in bps)Packet Size (in bits)
It is a fixed value according to the packet size and link bandwidth.
- Propagation Delay: The propagation delay is provided as a portion of the link configuration (10ms in the example) that is the fixed delay because of the physical distance among the nodes.
- Visualize the Network in NAM
We can also envision the packet flow in the network using the NAM file:
nam out.nam
Throughput this procedure, you can get to know more about how the Network Delay Assessment will be executed and evaluated including some examples. We offered the entire instructions of the implementation of it in the NS2 simulation tool. You can customize the simulation as per your requirements.
Our team guides you with your implementation by delivering results in Network Delay Assessment using the NS2 tool. Just share your project details with us, and we’ll guide you through the performance analysis process.