[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Loss Monitor



Hello.
I'm simulating a simple link error model with ns.
But I found there is a difference between the loss monitor result and the
queue monitor.
Could anyone can say about these results ?
# s0 ----- r0 ----- d0
Between the r0 node and the d0 node, there is a lossy link.
And several packets were dropped due to the error model.
But I found that the number of packet loss at the queue monitor doesn't
match that of lost packet at the receiver
by the LossMonitor.
What's happen and the difference?


simulation code
----------cut here---------
#
# s0 ----- r0 ----- d0
#


set ns [new Simulator]

$ns color 1 Blue


#Open the nam trace file
set nf [open out.nam w]
$ns namtrace-all $nf

#Define a 'finish' procedure
proc finish {} {
        global ns nf
        $ns flush-trace
        #Close the trace file
        close $nf
        #Execute nam on the trace file
        exec nam out.nam &
        exit 0
}

#source node 0
set s0 [$ns node]

#destination node 0
set d0 [$ns node]

#router 0 : gateway
set r0 [$ns node]

# making link from source node to router node 0
$ns duplex-link $s0 $r0 10Mb 1ms DropTail
$ns queue-limit $s0 $r0 1000

# making wireless link
$ns duplex-link $r0 $d0 1.5Mb 10ms DropTail
$ns queue-limit $r0 $d0 1000

# link position operation
$ns duplex-link-op $s0 $r0 orient right
$ns duplex-link-op $r0 $d0 orient right

#Monitor the queue for the link between r0 and  r1
$ns duplex-link-op $s0 $r0 queuePos 0.5
$ns duplex-link-op $r0 $d0 queuePos 0.5

# RTP version
# Associating source node s1 and destination node d1
set src0 [new Agent/RTP]
set sink0 [new Agent/LossMonitor]
$ns attach-agent $s0 $src0
$ns attach-agent $d0 $sink0
$ns connect $src0 $sink0
$src0 set fid_ 1

# RTP version
# Creating CBR packet flow 1
set e0 [new Application/Traffic/CBR]
$e0 attach-agent $src0
$e0 set interval_ 0.001
$e0 set packet_size_ 1400

# error on r0 --- d0 link
set lossylink [$ns link $r0 $d0]
set errmodel [new ErrorModel]
$errmodel set rate_ 0.5
$errmodel unit pkt
$errmodel ranvar [new RandomVariable/Uniform]
$errmodel drop-target [new Agent/Null]

set em [new ErrorModule Fid]
$lossylink errormodule $em
$em insert $errmodel
$em bind $errmodel 1

#
# Create a trace and arrange for all link events to be dumped to
"event-trace.out"
#
set tf [open event-trace.out w]
$ns trace-queue $r0 $d0 $tf
set qmon [$ns monitor-queue $r0 $d0 ""]
set integ [$qmon get-bytes-integrator]

#
# Dump the queueing delay on the r0->d0 link
# to stdout every second of simulation time.
#
proc dump { link interval } {
        global ns integ sink0 f0
        $ns at [expr [$ns now] + $interval] "dump $link $interval"
set lost_pkt [$sink0 set nlost_]
set rcv_pkt [$sink0 set npkts_]
set rcv_byte [$sink0 set bytes_]

        set delay [expr 8 * [$integ set sum_] / [[$link link] set
bandwidth_]]
        puts "[$ns now] delay=$delay, lost_pkts=$lost_pkt,
rcv_pkts=$rcv_pkt, rcv_bytes=$rcv_byte"
}

set f0 [open loss-rate.out w]
proc dump_loss_rate { } {
global sink0 f0

set lost_pkt [$sink0 set nlost_]
set rcv_pkt [$sink0 set npkts_]

        puts  $f0 " rcv_pkts=$rcv_pkt, lost_pkts=$lost_pkt"
}

set f1 [open transmission-rate.out w]
proc record { }  {
global sink0 f1
set ns [Simulator instance]
set time 1

set bw0 [$sink0 set bytes_]

set now [$ns now]

puts $f1 "$now [expr (($bw0/$time)*8)/1000]"

$sink0 set bytes_ 0
$ns at [expr $now+$time] "record"
}

$ns at 0.0 "record"
$ns at 0.0 "dump [$ns link $r0 $d0] 1"
$ns at 0.0 "$e0 start"
#$ns at 20.0 "$ns halt"
$ns at 20.0 "dump_loss_rate"
$ns at 20.0 "finish"
$ns run



------------------------------------------------------
Youngseok Lee
Multimedia & Computer Communication Lab.
Dept. of Computer Engineering, Seoul National Univ.

Tel : +82-2-876-7170
Fax : +82-2-876-7171
ICQ : 3668270
Email : [email protected]
URL : http://mmlab.snu.ac.kr/~yslee
------------------------------------------------------