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

[ns] question about queue size and flow delay caculation



hello, ns users
I use queue monitor and flow monitor to get queue size and flow delay.
when I use one of the two, it works well.
but it happen incorrect, when both of them are used.
my code is follows :
 
###########################
#    Proc
###########################
 
proc finish {} {
 global ns
 $ns flush-trace
 print_output
 exit
}
 
# print simulation output
proc print_output {} {
 global ns
 global start_time stop_time
 global tcp sink_num
 
 set total 0
 set packetsize 1460
 set sim_time [expr $stop_time - $start_time]
 
 for {set i 0} {$i < $sink_num} {incr i} {
  set throughput($i) [expr [$tcp($i) set t_seqno_] \
   * $packetsize * 8.0 / $sim_time /(1024*1024)]
  puts "flow [$tcp($i) set fid_] throughput [format "%6.2f" $throughput($i)]"
 }
 
 for {set j 0} {$j < $sink_num} {incr j} {
  set total [expr $total+$throughput($j)]
 } 
 puts "total throughput (in Mbps) [format "%6.2f" $total]"
}
 
# add error model, two state markov
proc add-error {LossyLink} {
      set loss_prob 0.015
 
      #set rv0 [new RandomVariable/Exponential] 
      #set rv1 [new RandomVariable/Exponential]
      #$rv0 set avg_ 1000
      #$rv1 set avg_ 1000
      
      set trans [list 0.001 0.999]
      set rate [list 100000000 1]
      set unit pkt
      set loss_module  [new ErrorModel/TwoStateMarkov $rate $trans $unit]
   
      #set loss_module [new ErrorModel/TwoState $rv0 $rv1]
      $loss_module drop-target [new Agent/Null]
      $loss_module set rate_ $loss_prob 
      $loss_module unit pkt
 
      $LossyLink errormodule $loss_module
}
 

# TCP cwnd trace
proc trace_cwnd {tcp_snd} {
 set tr_cwnd [open cwnd-flow0 w]
 $tcp_snd trace cwnd_
 $tcp_snd attach $tr_cwnd
}
 

proc create-topology {} {
 global ns fmon_
 global rcv_node snd_node bs
 global snd_node_num
 
 # bs connect to snders
        for {set i 0} {$i < $snd_node_num} {incr i} {
          $ns duplex-link $bs $snd_node($i) 100Mb 10ms DropTail
        }
     
        # we should set queue type, parameter
        set queuetype DropTail
        set queuesize 50
        set minthresh 12
 set maxthresh [expr $minthresh * 3]       
 
 Queue/RED set linterm_ 50
 Queue/RED set thresh_ $minthresh
 Queue/RED set maxthresh_ $maxthresh
 Queue/RED set limit_ $queuesize
 #Queue/RED set setbit_ true
 
 Queue/DropTail set limit_ $queuesize
 
 # bs connect to rcver
        $ns duplex-link $bs $rcv_node 2Mb 100ms $queuetype
     $ns duplex-link-op $bs $rcv_node queuePos 0.5
       
        set LossyLink [$ns link $bs $rcv_node]
        add-error $LossyLink   
       
        # monitoring queue
 #$ns attach-fmon [$ns link $bs $rcv_node] $fmon_
}
 
# flow monitoring
proc get_queue {} {
    global ns fmon_
    global sink_num
   
    set fcl [$fmon_ classifier]
    set total 0.0
    for {set i 0} {$i < $sink_num} {incr i} {
            set flow [$fcl lookup auto 0 0 $i]
            if { $flow != "" } {
                    set dsamp [$flow get-delay-samples]
      set mean [$dsamp mean]
      set total [expr $total + $mean]
                    puts "flow $i mean [format "%8.6f" $mean]"
            }
    }
    puts "mean delay (in seconds) [format "%8.6f" [expr $total / 2]]"
    puts "(A queue of 100 packets corresponds to delay of 0.017 seconds.)"
 
}
####################################
# Main Flow
####################################
 
set ns [new Simulator]
 
# sender, sink number
set snd_node_num 5
set sink_num 5
 
$ns color 0 red
$ns color 1 blue
 
# trace queue size
set dropq_ [open queue-test w]
 
# flow monitor
#set fmon_ [$ns makeflowmon Fid]
 
# make node and sink
# set rcv_node/snd_node, bs node
for {set i 0} {$i < $snd_node_num} {incr i} {
 set snd_node($i) [$ns node]
}
 
set bs [$ns node]
 
set rcv_node [$ns node]
 
create-topology
 
set qmon [$ns monitor-queue $bs $rcv_node $dropq_]
$qmon trace $dropq_
 
# we must make Agent!!
Agent/TCP/Reno set window_ 240
Agent/TCP/Reno set packetSize_ 1460
for {set i 0} {$i < $snd_node_num} {incr i} {
 set tcp($i) [new Agent/TCP/Reno]
 $tcp($i) set overhead_ 0.00017
 #$tcp($i) set ecn_ 1
 $tcp($i) set fid_ $i
 $ns attach-agent $snd_node($i) $tcp($i)
}
 
for {set i 0} {$i < $sink_num} {incr i} {
 set sink($i) [new Agent/TCPSink]
 $ns attach-agent $rcv_node $sink($i)
}
 
trace_cwnd $tcp(0)
 
for {set i 0} {$i < $sink_num} {incr i} {
 $ns connect $tcp($i) $sink($i)
}
 
for {set i 0} {$i < $sink_num} {incr i} {
 set ftp($i) [$tcp($i) attach-app FTP]
}
 
#########################
# Schedule #
#########################
 
set start_time 0.1
set middle_time 10.0
set stop_time 60.0
 
#$ns at 0.0 "record"
 
for {set i 0} {$i < $sink_num} {incr i} {
 $ns at $start_time "$ftp($i) start"
}
 
#for {set i 3} {$i < $sink_num} {incr i} {
# $ns at $middle_time "$ftp($i) start"
#}
 
for {set i 0} {$i < $snd_node_num} {incr i} {
 $ns at $stop_time "$ftp($i) stop"
}
 
set finish_time [expr $stop_time + 0.5]
$ns at $finish_time "finish"
 
$ns run
=======================================================
is anything incorrect in my code??????