How to Calculate Goodput in NS2
To Calculate the Goodput in the Network Simulator 2 (NS2) means the total of useful data transferred across the network without protocol overhead, retransmissions and packet losses. It is the crucial performance parameters in networking as it mirrors the actual helpful throughput from the application’s point of view.
Goodput is usually computed as the amount of successfully obtained application-level data bits at the destination over a particular time period. The formula for calculating Goodput is:
Goodput=Total received application data (in bits)Total simulation time (in seconds)\text{Goodput} = \frac{\text{Total received application data (in bits)}}{\text{Total simulation time (in seconds)}}Goodput=Total simulation time (in seconds)Total received application data (in bits)
Here’s a step-by-step guide on how to calculate Goodput in NS2:
Step-by-Step Implementation:
- Set Up NS2 to Simulate Data Transmission:
First, develop a basic simulation where a sender transfers data to a receiver. You need to capture the number of application-level data acquired at the destination and the time taken for the transmission.
Example TCL Script for Goodput Calculation:
# Create the simulator
set ns [new Simulator]
# Define the topology (e.g., 1000m x 1000m area)
set topo [new Topography]
$topo load_flatgrid 1000 1000
# Create two nodes
set node_(0) [$ns node]
set node_(1) [$ns node]
# Define the wireless channel
set chan_ [new Channel/WirelessChannel]
$node_(0) set channel_ $chan_
$node_(1) set channel_ $chan_
# Attach UDP agents for data transmission
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 CBR traffic (Constant Bit Rate)
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 512 ;# Packet size in bytes
$cbr0 set rate_ 1Mb ;# Data rate
# Start and stop the traffic
$ns at 1.0 “$cbr0 start”
$ns at 10.0 “$cbr0 stop”
# Enable tracing to capture packet reception at the destination
set tracefile [open out.tr w]
$ns trace-all $tracefile
# Finish the simulation and close trace file
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
}
# End simulation at 12 seconds
$ns at 12.0 “finish”
In this instance:
- The simulation delivers 512-byte packets from node 0 to node 1 at a rate of 1 Mbps.
- The simulation executes from time 1.0 seconds to 10.0 seconds.
- Trace File Analysis:
Measure the Goodput by extracting the application-level data successfully received at the destination node from the trace file. NS2 creates a trace file (out.tr) that logs packet transmission and reception events.
Trace File Example:
r 2.000000000 _1_ AGT — 512 cbr 0 0.0 1.0 1.0
r 3.000000000 _1_ AGT — 512 cbr 1 0.0 2.0 2.0
r 4.000000000 _1_ AGT — 512 cbr 2 0.0 3.0 3.0
Each line in the trace file indicates an event, where:
- r: Packet reception event.
- 2.000000000: Time at which the packet is received.
- _1_: Node ID (the destination node in this case).
- AGT: The application layer (relevant for Goodput calculation).
- 512: Packet size in bytes.
You need to extract the packets received at the application layer (AGT) for the destination node (_1_).
- Calculate Goodput:
Compute the Goodput by summing up the total number of application-level data (in bits) successfully received by the destination node and break down it by the simulation time.
AWK Script to Calculate Goodput:
BEGIN {
total_data = 0;
start_time = 1.0; # When traffic starts
end_time = 10.0; # When traffic stops
}
# Process received packets at the application layer (AGT)
$1 == “r” && $4 == “_1_” && $7 == “cbr” {
packet_size = $8; # Get packet size in bytes
total_data += packet_size * 8; # Convert to bits
}
END {
duration = end_time – start_time;
goodput = total_data / duration; # Goodput in bits per second (bps)
print “Total received data (bits): ” total_data;
print “Goodput (bps): ” goodput;
}
To execute the script, log it as goodput.awk, then execute it on your trace file:
awk -f goodput.awk out.tr
- Interpreting Goodput Results:
For instance, if the destination node successfully obtains 100 packets, each 512 bytes, the total amount of received data would be:
Total data (bits)=100×512×8=409600 bits\text{Total data (bits)} = 100 \times 512 \times 8 = 409600 \text{ bits}Total data (bits)=100×512×8=409600 bits
If the simulation time is 9 seconds (from 1.0 to 10.0 seconds), the Goodput would be:
Goodput=409600 bits9 seconds=45511.11 bps\text{Goodput} = \frac{409600 \, \text{bits}}{9 \, \text{seconds}} = 45511.11 \, \text{bps}Goodput=9seconds409600bits=45511.11bps
This value signifies the actual useful data rate received by the destination node except any retransmissions or overhead.
- Factors Affecting Goodput:
Goodput can be impacted by different factors:
- Packet Loss: If packets are dropped because of network congestion or errors, Goodput will decrease.
- Retransmissions: Excessive retransmissions decrease Goodput since only successfully received data is counted.
- Network Overhead: Protocol headers and retransmissions utilize bandwidth but don’t contribute to Goodput.
- Link Quality: Poor signal quality in wireless networks can cause higher packet loss, minimizing Goodput.
- Improving Goodput:
You can enhance Goodput by:
- Using error correction mechanisms to decrease packet loss.
- Maximizing the transmission power in wireless networks to improve link quality.
- Minimizing protocol overhead by using lightweight protocols where possible.
- Modifying traffic patterns to prevent congestion and packet collisions.
Conclusion:
To calculate Goodput in NS2:
- Set up a simulation where data is transmitted amongst nodes.
- Gather the received application-level data from the trace file using an AWK script or another analysis tool.
- Compute Goodput by breaking down the total received application data (in bits) by the total simulation time.
- Analyze the results to understand how network conditions impact the actual throughput seen by the application
In this computation, we successfully learned how to calculate the goodput using ns2 simulator tool and make sure to consider the provided few points before computing. If needed, we will offer additional details about it. We would appreciate it if you could share the specifics of your Goodput parameters, and we’ll be happy to help you enhance your project’s performance.