[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: WRR?
Jain
You can implement WRR using CBQ (Class-Based Queue). Configuring CBQ isn't
a simple task, and I'm attaching a little example. You can find a more
complete example in the test directory.
Carlos
On Sat, 8 Jan 2000, Chen Wen-Jen wrote:
> hello~~~ guys~~~
>
> I need to use the Weighted Round Robin algorithm
> in my simulation.
>
> Is there any WRR implementation in NS?
>
> Jay...
>
#Create a simulator object
set ns [new Simulator]
$ns color 1 Green
$ns color 2 Blue
$ns color 3 Black
set f_ef [open ds_ef.tr w]
set f_af [open ds_af.tr w]
set f_be [open ds_be.tr w]
#Define a 'finish' procedure
proc finish {} {
global f_ef f_af f_be
#Close the output files
close $f_ef
close $f_af
close $f_be
exec xgraph ds_ef.tr ds_af.tr ds_be.tr -geometry 700x400 &
exit 0
}
proc record {} {
global sink_ef f_ef sink_af f_af sink_be f_be
#Get an instance of the simulator
set ns [Simulator instance]
#Set the time after which the procedure should be called again
set time 0.25
#How many bytes have been received by the traffic sinks?
set bw_ef [$sink_ef set bytes_]
set bw_af [$sink_af set bytes_]
set bw_be [$sink_be set bytes_]
#Get the current time
set now [$ns now]
#Calculate the bandwidth (in MBit/s) and write it to the files
puts $f_ef "$now [expr $bw_ef/$time*8/1000000]"
puts $f_af "$now [expr $bw_af/$time*8/1000000]"
puts $f_be "$now [expr $bw_be/$time*8/1000000]"
#Reset the bytes_ values on the traffic sinks
$sink_ef set bytes_ 0
$sink_af set bytes_ 0
$sink_be set bytes_ 0
#Re-schedule the procedure
$ns at [expr $now+$time] "record"
}
#Create four nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Cria perfis de trafego
set p_ef [new DSPeakRateProfile]
$p_ef set-scope ONE_TO_ANY
$p_ef set src_ -1
$p_ef set peak_ 800000
$p_ef set deltat_ 0.02
$p_ef set-DSCP EF
# Cria perfis de trafego
set p_af [new DSPeakRateProfile]
$p_af set-scope ONE_TO_ANY
$p_af set src_ -1
$p_af set peak_ 300000
$p_af set deltat_ 0.02
$p_af set-DSCP AF11
$ns at 0.0 "$p_ef start"
#$ns at 0.0 "$p_af start"
# cria condicionadores de trafego
set cond_ef [new DSConditioner]
$cond_ef add-profile $p_ef
set cond_af [new DSConditioner]
$cond_af add-profile $p_af
#Cria os links entre os nos
$ns duplex-link $n0 $n3 1Mb 10ms DropTail
$ns duplex-link $n1 $n3 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns simplex-link $n3 $n4 1Mb 10ms CBQ/WRR
$ns simplex-link $n4 $n3 1Mb 10ms DropTail
set cbqlink [$ns link $n3 $n4]
# Insere o escalonador de filas WRR/CBQ
set topclass [new CBQClass]
# (topclass doesn't have a queue)
$topclass setparams none 0 1 auto 8 2 0
set classe_ef [new CBQClass]
set fila_ef [new Queue/DropTail]
$fila_ef set limit_ 40
$classe_ef install-queue $fila_ef
$classe_ef setparams $topclass true 0.4 auto 1 1 0
set classe_af [new CBQClass]
set fila_af [new Queue/DropTail]
$fila_af set limit_ 60
$classe_af install-queue $fila_af
$classe_af setparams $topclass true 0.4 auto 1 1 0
set classe_be [new CBQClass]
set fila_be [new Queue/DropTail]
$fila_be set limit_ 150
$classe_be install-queue $fila_be
$classe_be setparams $topclass true 0.2 auto 1 1 0
$cbqlink insert $topclass
$cbqlink insert $classe_ef
$cbqlink insert $classe_af
$cbqlink insert $classe_be
$cbqlink bind $classe_ef 1 ; # fid 1
$cbqlink bind $classe_af 2 ; # fid 2
$cbqlink bind $classe_be 3 ; # fid 3
# Insere os condicionadores na rede
$ns insert-conditioner $cond_ef $n0 $n3
#$ns insert-conditioner $cond_af $n1 $n3
# Agente EF
set cbr_ef [new Agent/CBR]
$ns attach-agent $n0 $cbr_ef
$cbr_ef set packetSize_ 500
$cbr_ef set interval_ 0.005
$cbr_ef set-DSCP EF
$cbr_ef set fid_ 1
set sink_ef [new Agent/LossMonitor]
$ns attach-agent $n4 $sink_ef
$ns connect $cbr_ef $sink_ef
# Cria um agente TCP/FTP e liga com o noh n1 - AF
set tcp_af [new Agent/TCP]
set sink_af [new Agent/TCPSink]
$ns attach-agent $n1 $tcp_af
$ns attach-agent $n4 $sink_af
$ns connect $tcp_af $sink_af
$tcp_af set fid_ 2
$tcp_af set-DSCP AF11
set ftp_af [$tcp_af attach-source FTP]
# Cria um agente TCP/FTP e liga com o noh n2 - BE
set tcp_be [new Agent/TCP]
set sink_be [new Agent/TCPSink]
$ns attach-agent $n2 $tcp_be
$ns attach-agent $n4 $sink_be
$ns connect $tcp_be $sink_be
$tcp_be set fid_ 3
$tcp_be set-DSCP BE
set ftp_be [$tcp_be attach-source FTP]
#Start logging the received bandwidth
$ns at 0.0 "record"
$ns at 5.0 "$cbr_ef start"
$ns at 5.0 "$ftp_af start"
$ns at 5.0 "$ftp_be start"
$ns at 55.0 "$cbr_ef stop"
$ns at 55.0 "$ftp_af stop"
$ns at 55.0 "$ftp_be stop"
$ns at 60.0 "finish"
#Run the simulation
$ns run