How to use Loss Monitor in ns2


Loss Monitor is attached with receiver node in TCL script. Loss Monitor objects trace out the lost packets, and received packets and stores the corresponding details. Packet Loss is measured by accessing the loss monitor object. Received bytes are obtained using inbuilt variable bytes

#Filename: sample13.tcl

#**************** Multiple node Creation and communication model using UDP (User Datagram Protocol) and LOSS MONITIOR ***************************

#******************************Defining Communication Between node0 and all nodes ****************************

proc calling { } {

global node_ ns r lm

set now [$ns now]

set time 3.0
for {set i 1} {$i < 10} {incr i} {
set udp [new Agent/UDP]
$ns attach-agent $node_(0) $udp

set cbr [new Application/Traffic/CBR]
$cbr set packetSize_ 512
$cbr set interval_ 0.07
$cbr attach-agent $udp

set lm($i) [new Agent/LossMonitor]
$ns attach-agent $node_($i) $lm($i)

$ns connect $udp $lm($i)
$ns at $now "$cbr start"
$ns at [expr $now + $time] "$cbr stop"

proc data { } {

global node_ ns lm r

set now [$ns now]

for {set i 1} {$i < 10} {incr i} {

set rd [$lm($i) set bytes_]
puts $r "$now received_bytes of node $i = $rd"