Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to calculate Packet Loss for wired network using awk script in NS2?

Description

Packet loss in a communication is the difference between the generated and received packets. Packet Loss is calculated using awk script which processes the trace file and produces the result.

Sample Code

# Filename: test12.tcl
#create links between the nodes

$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns simplex-link $n2 $n3 0.3Mb 100ms DropTail
$ns simplex-link $n3 $n2 0.3Mb 100ms DropTail
$ns duplex-link $n3 $n4 0.5Mb 40ms DropTail
$ns duplex-link $n3 $n5 0.5Mb 30ms DropTail
#Set Queue Size of link (n2-n3) to 10

$ns queue-limit $n2 $n3 20

$ns at 0.0 "$n0 label Sender1"
$ns at 0.0 "$n4 label Receiver1"

$ns at 0.0 "$n2 label Router1"
$ns at 0.0 "$n3 label Router2"

$ns at 0.0 "$n1 label Sender2"
$ns at 0.0 "$n5 label Receiver2"

#Setup a TCP connection

set tcp [new Agent/TCP/Newreno]
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink/DelAck]
$ns attach-agent $n4 $sink
$ns connect $tcp $sink
$tcp set fid_ 1
$tcp set window_ 8000
$tcp set packetSize_ 552

#Setup a FTP over TCP connection
set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP
#Setup a UDP connection

set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n5 $null
$ns connect $udp $null
$udp set fid_ 2

#Setup a CBR over UDP connection

set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 0.01mb
$cbr set random_ false

$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 10.0 "$ftp stop"
$ns at 10.5 "$cbr stop"
#Define a 'finish' procedure

proc finish {} {
global ns file1 file2
$ns flush-trace
close $file1
close $file2
exec nam test12.nam &
exec awk -f PacketLoss.awk test12.tr > output.tr &
exit 0
}
$ns at 12.0 "finish"
$ns run

############################################################

#Filename: PacketLoss.awk

#——— Formula ————:
Packet Loss = GeneratedPackets – ReceivedPackets

#——— AWK script Format——–#

The script has the following format:
BEGIN {}
{
content
}
END {}
Begin part comprises of initialization of variable.
Commands in the content part scan every row of trace file only once.
Ex:
if (pattern) {
action;
}

If the pattern is matched with the line in the trace in the trace file specified action will be performed.

In the END part final calculation is performed on the data obtained from the content part.

#——— Steps ————:
1. set pattern and action for received packets
2. set pattern and action for generated packets
3. Apply the result in formula

Screenshots

Congestion

file: output.tr
Dropped Packets = 21


calculate Packet Loss for wired network using awk script in ns2