How to Calculate Network Overhead in routing in NS2
To calculate Network overhead routing in ns2 often defined to the extra resources like bandwidth, time, and energy consumed by the control messages or routing-related data routed over the network. In NS2, network overhead in routing protocols that are AODV, DSDV, DSR, etc. and it the key metric to measure the effectiveness of the protocol. The routing overhead can be estimated as the number of control packets sent in the course of the simulation, relative to the total number of data packets transmitted. The below are the procedures to calculate the network overhead in routing in ns2:
Key Components of Routing Overhead:
- Control Packets: These are the packets used to introduce, maintain, and terminate routes. Instances that contain Route Request (RREQ), Route Reply (RREP), Route Error (RERR), HELLO packets, etc.
- Data Packets: These are the original packets that carry user data from the source to the destination.
Formula for Network Routing Overhead:
Routing overhead is usually estimated as the ratio of the number of control packets to the total number of data packets sent:
Routing Overhead=Number of Control PacketsNumber of Data Packets\text{Routing Overhead} = \frac{\text{Number of Control Packets}}{\text{Number of Data Packets}}Routing Overhead=Number of Data PacketsNumber of Control Packets
Steps to Calculate Routing Overhead in NS2:
- Run the Simulation with a Routing Protocol: initially, configure a simulation with a routing protocol like AODV, DSDV, or DSR. During the simulation, NS2 will create a trace file that logs all packet transmissions, has contain both control and data packets.
- Generate and Analyze the Trace File: The trace file has includes records of all sent, received, and forwarded packets. Each packet is marked with its type (control or data), and this can be extracted to estimate the number of control and data packets separately.
- Identify Control and Data Packets: we can utilize the trace file to differentiate among control packets such as RREQ, RREP, RERR and data packets (TCP, UDP, or CBR traffic). Routing overhead is estimated by summing up the control packets and comparing them to the number of data packets.
Example Tcl Script for NS2 Simulation:
Here’s a sample Tcl script that mimics a simple network using AODV as the routing protocol and logs the essential packet transmissions.
# Create a new simulator instance
set ns [new Simulator]
# Open a trace file to log packet transmissions
set tracefile [open trace.tr w]
$ns trace-all $tracefile
# Define the number of nodes and set up a wireless network
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(x) 500 ;# X dimension of the topography
set val(y) 500 ;# Y dimension of the topography
# Routing protocol (AODV)
set val(rp) AODV
# Create a topology object
create-god 5 ;# Create 5 nodes
# Create nodes
for {set i 0} {$i < 5} {incr i} {
set node($i) [$ns node]
$node($i) set X_ [expr rand()*$val(x)]
$node($i) set Y_ [expr rand()*$val(y)]
}
# Set up UDP connections and traffic between nodes
set udp [new Agent/UDP]
set null [new Agent/Null]
$ns attach-agent $node(0) $udp
$ns attach-agent $node(4) $null
$ns connect $udp $null
# Create CBR traffic source
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set rate_ 1Mb
# Start and stop the CBR traffic
$ns at 1.0 “$cbr start”
$ns at 5.0 “$cbr stop”
# Define finish procedure to close the trace file
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
}
# Schedule end of simulation
$ns at 10.0 “finish”
$ns run
- Trace File Analysis:
The trace file contains records for all packets sent, received, and forwarded in the course of the simulation. Each packet is acknowledged by its type that enables to separate control packets from data packets. The important fields in the trace file include:
- Packet Type (Control or Data): Control packets has involves AODV RREQ, RREP, RERR, and HELLO messages, since data packets refer to traffic such as TCP, UDP, or CBR.
Example Trace File Output:
s 1.0 _0_ AODV RREQ — 64 [0 0 0 0] ——- [1:0 2:0 32 0]
s 1.1 _0_ AGT — 512 [0 0 0 0] ——- [1:0 2:0 32 0]
r 1.2 _1_ AODV RREQ — 64 [0 0 0 0] ——- [1:0 2:0 32 0]
r 1.3 _1_ AGT — 512 [0 0 0 0] ——- [1:0 2:0 32 0]
- AODV: Refers to AODV control packets (e.g., RREQ, RREP, etc.).
- AGT: Refers to data packets (CBR, TCP, UDP).
- Counting Control and Data Packets:
Utilize grep and awk to sum the control packets (RREQ, RREP, etc.) and data packets distinctly.
Bash Script to Calculate Routing Overhead:
# Count the number of control packets (AODV RREQ, RREP, RERR, etc.)
control_packets=$(grep -e “AODV” trace.tr | wc -l)
# Count the number of data packets (AGT refers to application-level data)
data_packets=$(grep -e “AGT” trace.tr | wc -l)
# Calculate routing overhead
if [ $data_packets -gt 0 ]; then
routing_overhead=$(echo “scale=2; $control_packets / $data_packets” | bc)
echo “Routing Overhead: $routing_overhead”
else
echo “No data packets sent, unable to calculate routing overhead.”
fi
- Example Calculation:
Assume:
- Control Packets (RREQ, RREP, RERR, etc.) = 100
- Data Packets (AGT) = 50
The routing overhead is:
Routing Overhead=10050=2.0\text{Routing Overhead} = \frac{100}{50} = 2.0Routing Overhead=50100=2.0
This means that for every data packet sent, there are 2 control packets transmitted, that reflects the overhead established by the routing protocol.
Summary:
- Run the NS2 simulation using a routing protocol like AODV.
- Analyse the trace file to sum the number of control packets (RREQ, RREP, RERR) and data packets (TCP, UDP, CBR).
- Calculate the routing overhead by dividing the number of control packets by the number of data packets.
According to this procedure we have understood and aggregated the essential information regarding the computational procedures on Network overhead routing that includes the sample calculation process that were measured in ns2 tool. We will also offer more information about the Network overhead routing.
Tell us your parameter details, and we will help you with network comparison analysis. We assist you in calculating the Network Overhead in routing using the NS2 tool based on your project ideas. Our experts are ready to help you. We focus on routing protocols like AODV, DSDV, and DSR.