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

RE: Add queue



Hi, 

I was using the code Jeremy gave me to monitor a RED queue and tried to get
the average queue size. But it is so strange that when I look at the trace
file, average queue size is 0, while nam displayed there are some packets in
the queue. Also the last sample seems to be all zero in the trace file. I am
wondering what I am missing here. Or maybe I am using the Integrator object
in the wrong way? Would someone please take some time to look at the code
below? Thanks a lot.

Huiwen

**********************

#This is for Linespeed=1.5Mb/s, NumFlows=2, c/n=750kb/s

#create a simulator object

set ns [new Simulator]

$ns color 1 Blue
$ns color 0 Red

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

#define a 'finish' procedure
proc finish {} {
    global ns nf xf2
    $ns flush-trace
    #close the trace file
    close $nf
    close $xf2 
    exec nam out.nam &
    exec xgraph out2.tr -geometry 600x400 &
    exit 0
}

#create the topology
#create source nodes, destination nodes, and the intermediate nodes

set num 2           ;#parameters for topologies
set bw [expr 1.5*1000000]
set avgpktSize [expr 500*8]
set buffer 50
set stoptime 10.0

for {set i 0} {$i < $num} {incr i} {
    set SourceNode_($i) [$ns node]
    set DestNode_($i) [$ns node]
}
set r1 [$ns node]
set r2 [$ns node]
    
#create links between the nodes
for {set i 0} { $i < $num} {incr i} {
    $ns duplex-link $SourceNode_($i) $r1 500Mb 15ms DropTail
    $ns duplex-link $DestNode_($i) $r2 500Mb 15ms DropTail
}
$ns duplex-link $r1 $r2 $bw 20ms RED
#default queue size is 50
$ns queue-limit $r1 $r2 $buffer

#set up the queue monitor
set qmon [$ns monitor-queue $r1 $r2 $xf2]
$qmon set-pkts-integrator [new Integrator]
set ave [expr [[$qmon get-pkts-integrator] set sum_
]*$avgpktSize/$stoptime/$bw*1000]

#set parameters for RED queues

set redq1 [[$ns link $r1 $r2] queue] 
#default RED queue with max_p 0.1
#$redq1 set linterm_ 50
$redq1 set maxthresh_ 15

$ns duplex-link-op $r1 $r2 queuePos 0.5

#attach the applications and make connections

for {set i 0} {$i < $num} {incr i} {
    set tcp($i) [$ns create-connection TCP/Reno $SourceNode_($i) TCPSink
$DestNode_($i) $i]
    $tcp($i) set packetSize_ $avgpktSize
#default window_ is 20
#    $tcp($i) set window_ 30
    set ftp($i) [$tcp($i) attach-app FTP]
#    $telnet($i) set interval_ 0.001
    $ns at 0.0 "$ftp($i) start"
}

set x [[$qmon get-pkts-integrator] set lastx_]
set y [[$qmon get-pkts-integrator] set lasty_]
$ns at $stoptime [puts $xf2 "$x $y"]
$ns at $stoptime [puts $xf2 "$stoptime $ave"]
$ns at $stoptime "finish"
$ns run