⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runtest.tcl

📁 NSD2 QOS surpport tcl code
💻 TCL
字号:
# ns tcl test script # modified to use David Wei's Linux code # D.J.Leith, Hamilton Institute, 2007. # local functionsproc printtcp {fp tcp sink lastbytes rate T} {  global ns dt tcpTick  set now [$ns now]  if { $T >=1.0} {      set rate [expr ([$sink set bytes_]-$lastbytes)*8.0/(1000000*$T) ]      set lastbytes [$sink set bytes_]      set T 0.0   }  puts $fp "[format %.2f $now] [$tcp set cwnd_] [expr [$tcp  set srtt_]/8*$tcpTick*1000]  [$sink set bytes_] $rate"  $ns at [expr $now+$dt] "printtcp $fp $tcp $sink $lastbytes $rate [expr $T+$dt]"}proc print-tcpstats {tcp sink starttime label} {   global ns dt  set fp [open "$label.out" w]  set lastbytes 0  $ns at $starttime "printtcp $fp $tcp $sink 0 0 0"}proc printqueue {fp} {   global qmon fmon ns dt  set fcl [$fmon classifier]; # flow classifier  set drops1 0  set occupancy1 0  set bytes1 0  set loss1 0  set lossrate1 0  set drops2 0  set occupancy2 0  set bytes2 0  set loss2 0  set lossrate2 0   set flow [$fcl lookup auto 0 0 1]  if {$flow != "" } {  set drops1 [$flow set pdrops_]  set occupancy1 [expr [$flow set parrivals_] - [$flow set pdepartures_]-[$flow set pdrops_]]  set bytes1 [$flow set bdepartures_]  set loss1 [$flow set pdrops_]  if {[$flow set parrivals_] > 1} {set lossrate1 [expr ("[$flow set pdrops_].0")/[$flow set parrivals_]]}  }  set flow [$fcl lookup auto 0 0 2]  if {$flow != "" } {  set drops2 [$flow set pdrops_]  set occupancy2 [expr [$flow set parrivals_] - [$flow set pdepartures_]-[$flow set pdrops_]]  set bytes2 [$flow set bdepartures_]  set loss2 [$flow set pdrops_]  if {[$flow set parrivals_] > 1} {set lossrate2 [expr ("[$flow set pdrops_].0")/[$flow set parrivals_]]}  }  set now [$ns now]  set l [$qmon set pdrops_]  puts $fp "[format %.2f $now] [$qmon set pkts_] $l $l $bytes1 $bytes2 $loss1 $loss2 [$qmon set bdepartures_]"  $ns at [expr $now+$dt] "printqueue $fp"}proc print-qstats {fname} {   global ns   set fp [open $fname.out w]        $ns at 0.0 "printqueue $fp"}proc add_web_nodes {bdel randomize dir} {  global ns n3 n4  global sf_ rf_  global sb_ rb_  global count   if {$randomize == 0} {	set x [expr $bdel/2]ms	set y [expr $bdel/2]ms  } else {	set x [ns-random]	set y [ns-random]	set x [expr $bdel*($x/2147483647.0)]ms	set y [expr $bdel*($y/2147483647.0)]ms  }  set i $count  if {$dir == 0} {	set sf_($i) [$ns node]	set rf_($i) [$ns node]	$ns duplex-link $sf_($i) $n3 500Mb $x DropTail	$ns duplex-link $rf_($i) $n4 500Mb $y DropTail  } else {	set sb_($i) [$ns node]	set rb_($i) [$ns node]	$ns duplex-link $sb_($i) $n4 500Mb $x DropTail	$ns duplex-link $rb_($i) $n3 500Mb $y DropTail  }  incr count}proc add_web_traffic {bdel nums ip ps os flowid dir numWeb} {  global ns n3 n4  global sf_ rf_  global sb_ rb_  global count  global pool    #set numWeb 10  PagePool/WebTraf set FID_ASSIGNING_MODE_ 2  PagePool/WebTraf set TCPTYPE_ Sack1  PagePool/WebTraf set TCPSINKTYPE_ TCPSink/Sack1/DelAck  set pool [new PagePool/WebTraf]    $pool set-num-client $numWeb       $pool set-num-server $numWeb       $pool set sameFid_ $flowid  $pool set resp_trace_ 0  $pool set req_trace_ 0  for {set i 0} {$i < $numWeb} {incr i} {	add_web_nodes $bdel 0 $dir	if {$dir == 0} {	  $pool set-server $i $sf_([expr $count - 1])	  $pool set-client $i $rf_([expr $count - 1])	} else {	  $pool set-server $i $sb_([expr $count - 1])	  $pool set-client $i $rb_([expr $count - 1])	}  }  $pool set-num-session $nums  set numPage 10000  for {set i 0} {$i < $nums} {incr i} {	set interPage [new RandomVariable/Exponential]	$interPage set avg_ $ip	set pageSize [new RandomVariable/Constant]	$pageSize set val_ $ps	set interObj [new RandomVariable/Exponential]	$interObj set avg_ [expr 0.01]	set objSize [new RandomVariable/ParetoII]	$objSize set avg_ $os	$objSize set shape_ 1.2	$pool create-session $i $numPage 0 $interPage $pageSize $interObj $objSize   }}# get parameters ...set alphaopt_1 [lindex $argv 0]set alphaopt_2 [lindex $argv 1]set TCP_Name1 [lindex $argv 0]set TCP_Name2 [lindex $argv 1]set bw [lindex $argv 2]set rtt_1 [lindex $argv 3]set rtt_2 [lindex $argv 4]set qmax [lindex $argv 5]set web_sessions [lindex $argv 6]set endtime [lindex $argv 7]set stagger1 [lindex $argv 8]set stagger2 [lindex $argv 9]set iter [lindex $argv 10]set label [lindex $argv 11]set nslinux [lindex $argv 12]set scale [lindex $argv 14]set lambda [lindex $argv 15]set numclients [lindex $argv 16]set dt 0.1 ; # sampling interval (in seconds) used when logging cwnd etcset tcpTick 0.001remove-all-packet-headers       ; # removes all except commonadd-packet-header Flags IP TCP  ; # hdrs reqd for TCPset ns [new Simulator]ns-random 0Agent/TCP set ecn_ 0Agent/TCP set window_ 10000      ; # receiver's max window sizeAgent/TCP set packetSize_ 1460    ; # in bytes Agent/TCP set windowOption_ 1Agent/TCP set tcpTick_ $tcpTick# set up dumbbell topology ...set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]set n4 [$ns node]$ns duplex-link $n1 $n3 [expr $bw*2]Mb [expr $rtt_1/2-1]ms DropTail$ns duplex-link $n2 $n3 [expr $bw*2]Mb [expr $rtt_2/2-1]ms DropTail$ns duplex-link $n3 $n4 [expr $bw]Mb [expr 1]ms DropTailset BDP [expr $bw*1000*$rtt_1/1500/8]puts "BDP: $BDP"set q [expr $qmax*$BDP+1]puts "qmax: $q"if { $q <2} {set q 2}puts "queue size: $q"$ns queue-limit $n3 $n4 $q$ns queue-limit $n4 $n3 $qset qmon [$ns monitor-queue $n3 $n4 ""]set fmon [$ns makeflowmon Fid]$ns attach-fmon [$ns link $n3 $n4] $fmonprint-qstats "q_$label"if { $nslinux < 1} {    Agent/TCP set windowOption_ $alphaopt_1   set tcp [new Agent/TCP/Sack1]} else {   set tcp [new Agent/TCP/Linux]    $ns at 0 "$tcp select_ca $TCP_Name1"}set sink  [new Agent/TCPSink/Sack1/DelAck]set tcp [new Agent/TCP/Sack1]$tcp set fid_ 1$ns attach-agent $n1 $tcp$ns attach-agent $n4 $sink$ns connect $tcp $sinkset ftp [[set tcp] attach-app FTP]set starttime $stagger1$ns at $starttime "[set ftp] start"$ns at $endtime "[set ftp] stop"print-tcpstats [set tcp] [set sink] $starttime tcp1_$label ; #dump cwnd to file$ns at $starttime {puts "flow 1 starting..."}if { $nslinux < 1} {   Agent/TCP set windowOption_ $alphaopt_2   set tcp [new Agent/TCP/Sack1]} else {   set tcp [new Agent/TCP/Linux]   $ns at 0 "$tcp select_ca $TCP_Name2"}set sink  [new Agent/TCPSink/Sack1/DelAck]$tcp set fid_ 2$ns attach-agent $n2 $tcp$ns attach-agent $n4 $sink$ns connect $tcp $sinkset ftp [[set tcp] attach-app FTP]set starttime [expr $stagger1+$stagger2]$ns at $starttime "[set ftp] start"$ns at $endtime "[set ftp] stop"print-tcpstats [set tcp] [set sink] $starttime tcp2_$label ; #dump cwnd to file$ns at $starttime {puts "flow 2 starting..."}#puts "web_sessions $web_sessions"if { $web_sessions >0} {   set count 1#   add_web_traffic [expr $rtt_1/2-1] $web_sessions 4 10 1 100 0   add_web_traffic [expr $rtt_1/2-1] $web_sessions $lambda 1 $scale 100 0 $numclients   set count 1   add_web_traffic [expr $rtt_1-2] $web_sessions $lambda 1 $scale 120 1 $numclients}for {set i 0} {[expr 0 + ($i*10)] < $endtime} {incr i} {    set printtime [expr $i*10]    $ns at [expr 0 + $printtime] "puts $printtime"  }$ns at [expr $endtime + 2.0] "exit 0"puts "Starting Simulation..."$ns run

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -