-   Linux - Networking (
-   -   Monitoring TCP Packet Loss in NS2 (

yida 06-23-2010 12:48 PM

Monitoring TCP Packet Loss in NS2

I am simulating a TCP/FTP to TCP/FTP network and trying to monitor the packet loss.
I am able to monitor and graph data regarding the TCPSinks' bytes received, but I can't monitor packet loss.

Why is it that the TCPSink Agent has a variable for bytes (bytes_) but not one for monitoring packet loss?

Do I have to monitor the packet loss from the queue? If so, how do I write code for this?

Below is part of the code for monitoring bytes received from sinks if anyone was interested.

proc record {} {
global sink sink1 f0 f1 f2
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.3
#How many bytes have been received by the traffic sinks?
set bw0 [$sink set bytes_]
set bw1 [$sink1 set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $f0 "$now [expr $bw0/$time*8/1000000]"
puts $f1 "$now [expr $bw1/$time*8/1000000]"
#combination of f0 and f1
puts $f2 "$now [expr $bw0/$time*8/1000000+$bw1/$time*8/1000000]"
#Reset the bytes_ values on the traffic sinks
$sink set bytes_ 0
$sink1 set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"

Thank you for your help.

knudfl 06-23-2010 04:05 PM

May be try : Google .. Monitoring TCP Packet Loss in NS2 ..


knudfl 06-23-2010 04:05 PM

Sorry , browser hick up.


yida 06-24-2010 10:00 AM

I did a fairly extensive google search before posting here.
I've visited the two links above and could not find code for what I needed.

Does anyone see a bug in this code:

First monittor the queue

set qfile [$ns monitor-queue $n2 $n3 [open w] 0.05]
[$ns link $n2 $n3] queue-sample-timeout;

then write a prcodure to montior it

set prevDrops 0

proc record {} {
global ns qfile qsize qbw qlost n2 n3 prevDrops
set time 0.05
set now [$ns now]
$qfile instvar parrivals_ pdepartures_ bdrops_ bdepartures_ pdrops_
puts $qsize "$now [expr $parrivals_-$pdepartures_-$pdrops_]"
set bdepartures_ 0
set totalDrops [$qfile set pdrops_]
set currentDrops [expr $totalDrops - $prevDrops]
set prevDrops $totalDrops
puts $qlost "$now $currentDrops"
$ns at [expr $now+$time] "record"

knudfl 06-25-2010 08:06 AM

May be ask @ emtarik05 :

Posts by @ emtarik05 are here

All times are GMT -5. The time now is 11:44 PM.