Hi,
The tcl code is attached below. I am trying to simulate an M/M/1 queue for a
duration of 9000 seconds, and I want to reset the queue-monitor counters
after every 3000 seconds in order to obtain confidence intervals for
calculating mean queue lengths and waiting times.
The problem is that I am getting negative values for queue lengths (i.e.
parrivals_ - pdepartures_) after I reset the queue-monitor.
Any ideas why this is so. Am I missing something in my code?
#Tcl Script START (m/m/1)
set ns [new Simulator]
set plotfile [open mm1.tr w]
set lambda 30.0
set mu 33.0
set duration 900.0
set n1 [$ns node]
set n2 [$ns node]
set link [$ns simplex-link $n1 $n2 100kb 0ms DropTail]
$ns queue-limit $n1 $n2 100000
set InterArrivalTime [new RandomVariable/Exponential]
$InterArrivalTime set avg_ [expr 1/$lambda]
set pktSize [new RandomVariable/Exponential]
$pktSize set avg_ [expr 100000.0/(8*$mu)]
set src [new Agent/UDP]
$ns attach-agent $n1 $src
set qmon [$ns monitor-queue $n1 $n2 [open qm.out w] 0.1]
$link queue-sample-timeout
proc finish {} {
global ns plotfile
$ns flush-trace
close $plotfile
exit 0
}
proc sendpacket {} {
global ns src InterArrivalTime pktSize duration
set time [$ns now]
if {$time < $duration} {
$ns at [expr $time + [$InterArrivalTime value]] "sendpacket"
}
set bytes [expr round ([$pktSize value])]
$src send $bytes
}
proc plotFunc {file} {
global ns qmon
set time 0.1
set now [$ns now]
set nexttime [expr $now+$time]
$qmon instvar parrivals_ pdepartures_ pdrops_ size_ pkts_ bytesInt_
pktsInt_
puts $file "$now $parrivals_ $pdepartures_ $pdrops_ [expr
$parrivals_-$pdepartures_ $pdrops_]"
$ns at $nexttime "plotFunc $file"
}
$ns at 1.0 "plotFunc $plotfile"
$ns at 300.0 "$qmon reset"
$ns at 600.0 "$qmon reset"
set sink [new Agent/Null]
$ns attach-agent $n2 $sink
$ns connect $src $sink
$ns at 0.0001 "sendpacket"
$ns at $duration "finish"
$ns run
#Tcl script END